# Deloitte USI DSA Questions with Answers

6 previously-asked dsa questions from Deloitte USI'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 all duplicate elements in an array.

**Answer:** Use a hash set of seen values (or a frequency map). Iterate the array; if an element is already in the set it is a duplicate, otherwise add it. Time O(n), space O(n).

**Explanation:** Track seen values in a hash set.

### 2. Compute the digital root of a number (repeatedly sum digits until one digit remains).

**Answer:** Loop: while the number has more than one digit, replace it with the sum of its digits. Alternatively use the formula 1 + (n - 1) mod 9 for n greater than 0. Time O(number of digits).

**Explanation:** Repeated digit sum, or the mod 9 formula.

### 3. Find the majority element that appears more than n/2 times in an array.

**Answer:** Use the Boyer-Moore voting algorithm: keep a candidate and a count; increment when the element matches the candidate, decrement otherwise, and switch the candidate when the count hits 0. Verify with a second pass. Time O(n), space O(1).

**Explanation:** Boyer-Moore voting algorithm.

### 4. Reverse the order of words in a sentence.

**Answer:** Split the sentence on spaces into words, reverse the list of words, and join them back with single spaces. Handle extra spaces. Time O(n).

**Explanation:** Split, reverse the word list, join.

### 5. Find the longest common prefix among an array of strings.

**Answer:** Take the first string as a reference and compare character by character across all strings, stopping at the first mismatch or the shortest string end. Return the matched prefix. Time O(total characters).

**Explanation:** Vertical scanning across strings.

### 6. Check whether a given number is prime.

**Answer:** Numbers below 2 are not prime. Otherwise test divisibility from 2 up to the square root of n; if none divides n it is prime. Time O(square root of n).

**Explanation:** Trial division up to the square root.

More Deloitte USI preparation, including the full recruitment process: https://useastra.in/campus/deloitte
