Citi interview prep
6 practice questions on the topics candidates reported from Citi interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
A queue is built from two stacks. Enqueue pushes onto stack A. Dequeue pops from stack B, first moving everything from A to B if B is empty. What is the amortised cost per operation?
- O(n)
- O(log n)
- O(1)
- O(n^2)
Show the answer
C. O(1)
One dequeue can move n elements, but each element is pushed and popped at most twice in its life (once on A, once on B), so n operations cost O(n) in total.
This topic is named in a candidate’s interview report: On-campus interview, 2021, on GeeksforGeeks.
-
The i-th code of the n-bit reflected Gray code is i XOR (i >> 1). What is the 3-bit Gray code sequence?
- 000 001 010 011 100 101 110 111
- 000 011 110 101 100 111 010 001
- 000 001 011 010 110 111 101 100
- 000 010 110 100 101 111 011 001
Show the answer
C. 000 001 011 010 110 111 101 100
For i = 0 to 7, i XOR (i >> 1) gives 0, 1, 3, 2, 6, 7, 5, 4. Consecutive codes, and the last and first, differ in exactly one bit.
This topic is named in a candidate’s interview report: Software developer on-campus interview, 2020, on GeeksforGeeks.
-
What is the GCD of the array [12, 18, 30]?
- 3
- 2
- 12
- 6
Show the answer
D. 6
GCD works pairwise: gcd(12, 18) = 6 and gcd(6, 30) = 6. Folding Euclid's algorithm over the array is O(n log m) for values up to m.
This topic is named in a candidate’s interview report: On-campus interview, 2021, on GeeksforGeeks.
-
A grid maze has open cells and walls. Which approach tells you whether the cheese can be reached from the start?
- Sort the cells by row
- A depth-first or breadth-first search from the start over open neighbouring cells, marking each cell visited
- Binary search over the rows
- Dijkstra's algorithm with negative weights
Show the answer
B. A depth-first or breadth-first search from the start over open neighbouring cells, marking each cell visited
Reachability is a graph search: each open cell is a node joined to its open neighbours. Marking cells visited keeps it O(rows x columns). BFS also gives the shortest path length.
This topic is named in a candidate’s interview report: Programmer analyst on-campus interview, 2021, on GeeksforGeeks.
DBMS and SQL 2
-
What is the difference between GROUP BY and ORDER BY?
- They mean the same thing
- GROUP BY collapses rows with equal values into one row per group, usually with aggregates such as COUNT; ORDER BY only sorts the result rows
- ORDER BY removes duplicate rows
- GROUP BY sorts in descending order and ORDER BY in ascending order
Show the answer
B. GROUP BY collapses rows with equal values into one row per group, usually with aggregates such as COUNT; ORDER BY only sorts the result rows
SELECT dept, COUNT(*) FROM emp GROUP BY dept returns one row per department. Adding ORDER BY COUNT(*) DESC then sorts those rows; ORDER BY never changes how many rows there are.
This topic is named in a candidate’s interview report: Software developer on-campus interview, 2020, on GeeksforGeeks.
-
What does this query return?
SELECT name FROM emp WHERE salary > (SELECT AVG(salary) FROM emp);- The average salary
- An error, because subqueries are not allowed in WHERE
- The names of employees paid more than the average salary
- The name of the highest-paid employee
Show the answer
C. The names of employees paid more than the average salary
The inner query runs first and returns one number, the average. The outer query then keeps each row whose salary is above it. A subquery that returns a single value can be used anywhere a value can.
This topic is named in a candidate’s interview report: Technology analyst on-campus interview, 2021, on GeeksforGeeks.