GeeksforGeeks » Interview Questions

worksApp interview question

(2 posts)
  1. arindam
    Member
    Posted 8 months ago #

    implement a stack which will support three additional operations in addition to push and pop:
    1.peekLowestElement()//return the lowest element in the stack without removing it from the stack
    2.peekHighestElement()//return the highset element in the stack without removing it from the stack
    3.peekMiddleElement()//return the (size/2 +1)th lowest element in the stack without removing it from the stack.

    faster is better.Assume every method will be called with equal frequency.

  2. google
    Member
    Posted 8 months ago #

    If we consider array based implementation of stack , then all the three operations can be done in constant time.
    we need to store index of maximum and minimum elements in stack and compare the value at each push() ..


Reply

You must log in to post.

RSS feed for this topic