Adobe interview prep
9 practice questions on the topics candidates reported from Adobe interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
Two singly linked lists join at some node and share every node after it. Two pointers walk the lists, and each jumps to the head of the other list when it reaches the end. Why do they meet at the joining node?
- Because the two lists always have the same length
- Before reaching the shared part, both have walked the same distance: the first list's own nodes plus the second list's own nodes plus the shared tail once
- Because one pointer moves twice as fast as the other
- They do not; this only detects a cycle
Show the answer
B. Before reaching the shared part, both have walked the same distance: the first list's own nodes plus the second list's own nodes plus the shared tail once
If the lists are a + c and b + c long, with c shared, one pointer walks a + c + b and the other b + c + a before entering the shared part, so they arrive together. O(m + n) time, O(1) space. If the lists never join, both reach null at the same moment.
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
-
You build a height-balanced binary search tree from a sorted array. Which element becomes the root?
- The first element
- The last element
- The middle element; the left half builds the left subtree and the right half the right subtree
- Any element, followed by rotations to balance it
Show the answer
C. The middle element; the left half builds the left subtree and the right half the right subtree
Taking the middle each time splits what is left evenly, so the two sides of every node differ in height by at most one. Each element is placed once, in O(n) time.
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
-
A spell checker must say whether a word is in its dictionary and list the dictionary words that start with what was typed. Which data structure suits this best?
- A trie (prefix tree)
- A stack
- A min-heap
- A queue
Show the answer
A. A trie (prefix tree)
A trie answers both "is this a word?" and "which words start with this?" in time proportional to the word's length. For "Did you mean" suggestions, spell checkers add an edit-distance search over the trie.
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
-
Every tower's height must be raised or lowered by exactly k, once. To make the gap between the tallest and shortest tower as small as possible, the usual method sorts the heights first. Why does sorting help?
- Sorting makes all the heights equal
- Sorted heights can all be changed by k in O(1) total
- Some best answer raises a prefix of the sorted heights and lowers the rest, so only the n - 1 split points need trying
- Sorting lets binary search find k
Show the answer
C. Some best answer raises a prefix of the sorted heights and lowers the rest, so only the n - 1 split points need trying
Raising a taller tower while lowering a shorter one never helps more than the opposite, so try each split: raise the first i towers, lower the others, and keep the smallest gap. The sort makes it O(n log n).
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
Python 1
-
What does this print?
n = 3 for i in range(1, n + 1): print(" " * (n - i) + "*" * (2 * i - 1))- A right-angled triangle of 1, 2 and 3 stars
- Three rows of 3 stars
- A centred pyramid of 1, 3 and 5 stars
- An upside-down pyramid of 5, 3 and 1 stars
Show the answer
C. A centred pyramid of 1, 3 and 5 stars
Row i has n - i leading spaces and 2i - 1 stars: " *", " ***" and "*****". The spaces shrink as the stars grow, which centres each row.
This topic is named in a candidate’s interview report: CE-DX campus interview, 2024, on Reddit.
C and C++ 2
-
In C++, what does new do that malloc does not?
- It frees the memory automatically when the function returns
- It allocates on the stack instead of the heap
- It runs the object's constructor (and delete runs the destructor)
- It always returns NULL on failure instead of crashing
Show the answer
C. It runs the object's constructor (and delete runs the destructor)
malloc only reserves raw bytes. new reserves memory and constructs the object in it, and delete destroys it before freeing. By default new throws std::bad_alloc on failure rather than returning null.
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
-
In a C program, a function declares static int calls = 0; inside it. Where is calls stored?
- On the stack, created fresh on every call
- On the heap, freed when the function returns
- With the globals, in the data area (BSS here, since it starts at zero); it keeps its value between calls
- Only in a CPU register
Show the answer
C. With the globals, in the data area (BSS here, since it starts at zero); it keeps its value between calls
Static and global variables live for the whole run, in the data segment, or BSS when they start at zero. Ordinary local variables sit on the stack and vanish when the function returns. Memory from malloc or new is on the heap until it is freed.
This topic is named in a candidate’s interview report: MTS on-campus interview, on GeeksforGeeks.
DBMS and SQL 2
-
Which of these is a DML command rather than a DDL command?
- CREATE
- ALTER
- DROP
- UPDATE
Show the answer
D. UPDATE
DML (data manipulation) changes the rows: INSERT, UPDATE, DELETE and, by most definitions, SELECT. DDL (data definition) changes the structure: CREATE, ALTER, DROP and TRUNCATE.
This topic is named in a candidate’s interview report: CE-DX campus interview, 2024, on Reddit.
-
emp has rows for 6 employees in the cities Delhi, Pune, Delhi, Mumbai, Pune and Delhi. How many rows does SELECT DISTINCT city FROM emp; return?
- 6
- 2
- 1
- 3
Show the answer
D. 3
DISTINCT removes duplicate result rows, leaving Delhi, Pune and Mumbai. COUNT(DISTINCT city) would return the single number 3.
This topic is named in a candidate’s interview report: CE-DX campus interview, 2024, on Reddit.