KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was asked this question in an interview.The problem was i would be given a stack and have to find the element in the middle position of the stack."top" index is not available (so that you don't pop() top/2 times and return the answer).Assume that you will reach the bottom of the stack when pop() returns -1.Don't use any additional data structure. Eg: stack index ----- 2 nth element 3 99 . 1 n/2 th element . -1 bottom of the stack(0th index) Answer: 1 (I didn't mean the median.Find the element in middle position) Is recursion the only way? Thanks, psy
Tags (comma-separated)
Save Edits
Cancel