# Adobe DSA Questions with Answers

8 previously-asked dsa questions from Adobe's hiring process, each with the correct answer and a worked explanation. Written against the company's actual test pattern.

_Source: Astra (https://useastra.in). Updated 2026-09-05._

### 1. Find the majority element that appears more than n/2 times.

**Answer:** Use Boyer-Moore voting: keep a candidate and count, increment on a match, decrement otherwise, switch candidate at count 0. Verify with a second pass. Time O(n), space O(1).

**Explanation:** Boyer-Moore voting.

### 2. Implement a stack using a linked list.

**Answer:** Keep a head pointer as the top. push inserts a node at the head; pop removes and returns the head node. Both are O(1); the stack grows dynamically.

**Explanation:** Linked list with head as top.

### 3. Find the maximum sum of a contiguous subarray.

**Answer:** Use Kadane algorithm: keep a running sum, reset it to the current element when it drops below that element, and track the best. Time O(n), space O(1).

**Explanation:** Kadane algorithm.

### 4. Check whether two binary trees are identical.

**Answer:** Recurse in parallel: both nodes null means equal; one null or differing values means not equal; otherwise compare left and right subtrees. Time O(n).

**Explanation:** Parallel recursion on both trees.

### 5. Reverse a stack using recursion, without another explicit stack.

**Answer:** Recursively pop all elements, then insert each popped element at the bottom of the stack using a helper that recurses to the base. Time O(n^2), using the call stack.

**Explanation:** Recursive insert-at-bottom.

### 6. Find the common elements (intersection) of two arrays.

**Answer:** Add the first array to a hash set, then collect elements of the second array present in the set, using another set to avoid duplicates. Time O(m + n).

**Explanation:** Hash set membership.

### 7. Convert a sorted array into a height balanced binary search tree.

**Answer:** Pick the middle element as the root, then recursively build the left subtree from the left half and the right subtree from the right half. Time O(n).

**Explanation:** Middle element as root, recurse on halves.

### 8. Find the length of the longest consecutive sequence in an unsorted array.

**Answer:** Put all numbers in a hash set. For each number that has no predecessor (n-1 not in set), count upward while successors exist, tracking the max length. Time O(n).

**Explanation:** Hash set, extend runs from sequence starts.

More Adobe preparation, including the full recruitment process: https://useastra.in/campus/adobe
