Question 51
MediumWhat is the first non-repeating character after each character of the stream 'aabc'?
- A.
a, b, c, c
- B.
none, none, b, c
- C.
a, a, b, c
- D.
a, none, b, b
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the first non-repeating character after each character of the stream 'aabc'?
a, b, c, c
none, none, b, c
a, a, b, c
a, none, b, b
Sign up free to see the answer and a step-by-step explanation.
Which queue gives each element a priority and serves the highest first?
Priority queue
Circular queue
Deque
Simple FIFO queue
Sign up free to see the answer and a step-by-step explanation.
What is the space complexity of BFS on a graph with V vertices?
O(1)
O(V)
O(log V)
O(E²)
Sign up free to see the answer and a step-by-step explanation.
In a queue implemented with a singly linked list, which pointers make both enqueue and dequeue O(1)?
Only a head pointer
A head pointer for dequeue and a tail pointer for enqueue
Only a tail pointer
A middle pointer
Sign up free to see the answer and a step-by-step explanation.
In an array-based circular queue of capacity n, how can a full queue be told apart from an empty one if both have front == rear?
Keep a count of elements (or leave one slot unused)
It is impossible
Check whether the array is sorted
Use a second array
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from collections import deque
g = {1: [2, 3], 2: [4], 3: [4], 4: []}
seen, q, order = {1}, deque([1]), []
while q:
u = q.popleft()
order.append(u)
for v in g[u]:
if v not in seen:
seen.add(v)
q.append(v)
print(order)
[2, 4, 1, 3]
[4, 3, 2, 1]
[1, 2, 3, 4]
[1, 3, 2, 4]
Sign up free to see the answer and a step-by-step explanation.
A queue initially holds 1, 2, 3, 4, 5 (front to back). Two operations are repeated 3 times: dequeue x, then enqueue x. What is at the front?
3
5
4
1
Sign up free to see the answer and a step-by-step explanation.
Which data structure gives O(1) access to the maximum of the last k elements of a stream as it slides?
A monotonic deque
A stack
A plain queue
A linked list
Sign up free to see the answer and a step-by-step explanation.
In the 'rotten oranges' grid problem, why is multi-source BFS used?
It needs a stack
All rotten oranges spread at the same time, so they all start in the queue at level 0
To sort the oranges
DFS can't visit grids
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
from collections import deque
d = deque([1, 2, 3, 4, 5])
d.rotate(-1)
print(d)
deque([1, 2, 3, 4, 5])
deque([5, 1, 2, 3, 4])
deque([3, 4, 5, 1, 2])
deque([2, 3, 4, 5, 1])
Sign up free to see the answer and a step-by-step explanation.