Array Division to Three Stacks LeetCode (Creating 3 Stacks with 1 Array)

Given an array, divide it into 3 stacks. You need to implement the push, peek, and pop methods similar to basic Stack.

  1. push(Stack st, int a): The push operation will be given the stack to push and the value to push.
  2. pop(Stack st): The pop operation will be given the stack to pop from.
  3. peek(Stack st): The peek operation will be given the stack to pop from.

The underlying array should be used to act as Stack and operate the push, pop, and peek methods as defined above.

This problem is simple array manipulation problem and is well discussed in several forums, such as StackOverFlow and GeeksForGeeks A collection of hundreds of interview questions and solutions are available in our blog at Interview Question


Solution

No comments:

Post a Comment