Question 51
MediumHow many elements can a stack of capacity 5 hold after push, push, pop, push, push, push, pop, push?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
How many elements can a stack of capacity 5 hold after push, push, pop, push, push, push, pop, push?
5
4
6
3
Sign up free to see the answer and a step-by-step explanation.
What does a stack-based approach do for the 'decode string' problem 3[a2[c]]?
Reverses the string
Sorts characters
Counts vowels
Pushes counts and partial strings, building 'accaccacc'
Sign up free to see the answer and a step-by-step explanation.
Which pair is used by Dijkstra's two-stack algorithm to evaluate infix expressions?
An operand stack and an operator stack
A stack and a queue
Two operand stacks
Two queues
Sign up free to see the answer and a step-by-step explanation.
The call sequence main → f → g → h is running. Which function returns first?
h
g
main
f
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
h = [2, 1, 5, 6, 2, 3]
st, best = [], 0
for i, x in enumerate(h + [0]):
while st and h[st[-1]] >= x:
height = h[st.pop()]
width = i if not st else i - st[-1] - 1
best = max(best, height * width)
st.append(i)
print(best)
8
6
Sign up free to see the answer and a step-by-step explanation.
What is the postfix form of (A + B) * (C − D) / E?
A B C D + − * E /
A B + C D − * E /
A B + C D − E / *
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
t = [73, 74, 75, 71, 69, 72, 76, 73]
res = [0] * len(t)
st = []
for i, x in enumerate(t):
while st and t[st[-1]] < x:
j = st.pop()
res[j] = i - j
st.append(i)
print(res)
[0, 0, 4, 2, 1, 1, 0, 0]
[1, 1, 4, 2, 1, 1, 0, 0]
Sign up free to see the answer and a step-by-step explanation.
A stack receives push(1), push(2), push(3) in that order, with pops allowed at any time. Which output sequence is impossible?
3 2 1
3 1 2
2 3 1
1 2 3
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
st = []
for x in [2, 0, -1]:
st.append((x, min(x, st[-1][1]) if st else x))
print(st[-1][1])
-1
0
Sign up free to see the answer and a step-by-step explanation.
How many stacks are needed to evaluate an infix expression directly (Dijkstra's two-stack algorithm)?
One
Two: one for operands and one for operators
None
Three
Sign up free to see the answer and a step-by-step explanation.
12
10
[1, 4, 2, 1, 1, 0, 0, 0]
[1, 1, 1, 1, 1, 1, 0, 0]
Error
2