## Stacks Interview Questions

- 0of 0 votes
https://codejamanalysis.wordpress.com/2017/03/18/crossover-problem-super-stack/

Any Optimized Solution to avoid TLE for 4 test cases. I have tried by implementing Stack using Doubly Linked List.

Still not able to pass test cases!!!

- 1of 1 vote
Given an extremely large file that contains parenthesis, how would you say that the parenthesis are balanced?

The file cannot fit in the memory. How would you process the file and how would you store the intermediate results.

Walk me through the entire algorithm.`Examples: {[()]}, {[](){}}, [] are some valid examples.`

- 0of 0 votes
Implement stack using a queue.

- 0of 0 votes
You are given two Queues where each queue contains timestamp price pair. You have to print <price1 price 2> pair for all those timestamps where abs(ts1-ts2) <= 1 second where ts1 and price1 are the from the first queue and ts2 and price2 are from the second queue.

Now let's say one queue is slow, what kind of modification you will make?

- 0of 0 votes
Q 4. You are given a binary tree, and you have to return list of lists of node. where same level nodes should be in the same list, nodes are in opositive order in next list from the previous list

Ex:`4 / \ 3 5 / \ \ 1 10 -4`

Output would be

[[4], [5, 3], [1, 10, -4]]

Desigred Complexity : O(N) + O(N).

- 0of 0 votes
Sort a stack using only one other stack and no recursion.

- 0of 0 votes
In my First round, very first question that guy asked me is to generate an algorithm to check whether string is palindrome or not. After that in the same round, he asked me to create a class that duplicates the Stack property.

First, String Palindrome:

Used stringbuilder, i.e.`StringBuilder sb = new StringBuilder(str); System.out.println(sb.reverse());`

then he told me to not to use StringBuilder, so i convert string into the char array, then apply loop till half the size of the string. and check character by character. He said ok. "looks good".

- 1of 3 votes
design and implement a calculater that can calculate expressions like:

+ 2 4

* 8 ( + 7 12)

( + 7 ( * 8 12 ) ( * 2 (+ 9 4) 7 ) 3 )

(PS:all items are space delimetered.)

Example answers

+ 2 4 => 2 + 4 = 6

* 8 ( + 7 12) => 8 * ( 7 + 12 ) = 152

( + 7 ( * 8 12 ) ( * 2 (+ 9 4) 7 ) 3 ) => 7+8*12+2*(9+4)*7+3 = 148

- 0of 0 votes
find if linked list is palindrome

a -> b-> Null

- 1of 1 vote
Sort the elements inside a stack using only push and pop opperation. Is it possible to do it only with one additional stack?

- 3of 5 votes
Write a program to implement Double Linked List from Stack with min. complexity.

- 0of 0 votes
Design a stack using queue(s)

- 0of 2 votes
Design a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .

- 1of 1 vote
Given a mathematical expression, remove the redundant brackets from the expression.

`e.g. input: (a + (b*c)) * (d * ( f * j) ) output should be: (a + b * c) *d * f * J`

- 4of 4 votes
give an algorithm for finding duplicate parenthesis in a expression.

example :`(( a + b ) + (( c + d )))`

- 1of 1 vote
give an algorithm for finding duplicate parenthesis in a expression.

{{ (( a + b ) * (( c + d ))) }}

- 1of 3 votes
One of the questions in one of the interviews -

Given a stack S and another empty stack T and a variable v, write a function that returns S but with its elements reversed.

- 3of 3 votes
Implement a stack with O(1) push, pop, and min

- -5of 7 votes
need to implement a weather report functionality. user will provide the city name , need to return the weather report.

if weather station exists n functioning properly , will return the weather report of that station .

else ,

will return the nearest available weather station report.

interviewer looking for optimized manner.

looking for datastructures to stores the cities n algo to return the report.

- 3of 3 votes
Q: Do you know what is a stack? Explain

A: Yes, explained LIFO push pop peek

Q: In stack, Push and Pop are constant. What will you do if you want an operation which gives the min of the stack also in constant time?

A: Question is straight out of Gayle's Book. You just maintain a new stack of minimum number till that point.

- -1of 1 vote
Implement Queue using stacks

- 0of 0 votes
Find the minimum element in a stack in O(1) time complexity and O(n) space complexity

- 0of 0 votes
Reverse a stack without using extra stack (i.e. doing in place reversal). (hinted about using double recursion).

- 0of 0 votes
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.

- 0of 0 votes
Implement enqueue and dequeue operations using stack(s).

- 0of 0 votes
how to convert a queue into stack

- 0of 0 votes
There is a stack class which does push & pop in constant time. Introduce another function called min() which returns min element in the stack.

- 0of 0 votes
Implement Queue using Stack.

- 0of 0 votes
Five boxes, A through E, are stacked in alphabetical order with box A on top. The bottom three boxes are simultaneously removed and placed on top with their vertical order maintained. If this procedure were repeated two more times which box would end up in the middle of the stack?

Box E

Box D

Box C

Box A

Box B

- 1of 1 vote
Implement enqueue and dequeue for a stack.

class stack

{

push(int i)

pop()

count() : count the number of elements in stack

} is given.