# Oracle DSA Questions with Answers

8 previously-asked dsa questions from Oracle'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. Compute the nth Fibonacci number efficiently.

**Answer:** Iterate with two variables updated n times for O(n) time and O(1) space, or use memoisation. Avoid naive recursion which is exponential.

**Explanation:** Iterative two-variable approach.

### 2. Check whether a string is a palindrome.

**Answer:** Use two pointers from both ends comparing characters until they meet. Optionally ignore case and non-alphanumeric characters. Time O(n).

**Explanation:** Two-pointer comparison.

### 3. Find the second largest element in an array.

**Answer:** Track the largest and second largest in one pass, updating them as larger values appear and skipping duplicates of the largest. Time O(n).

**Explanation:** Single pass tracking top two.

### 4. Remove duplicates from an unsorted linked list.

**Answer:** Use a hash set of seen values; traverse the list and unlink any node whose value is already in the set. Time O(n), space O(n). Without extra space, use two pointers in O(n^2).

**Explanation:** Hash set of seen values.

### 5. Count the total number of nodes in a binary tree.

**Answer:** Recurse: the count is 1 plus the counts of the left and right subtrees, with 0 for a null node. Time O(n).

**Explanation:** Recursive node count.

### 6. Add two numbers represented as linked lists of digits.

**Answer:** Traverse both lists together adding corresponding digits with a carry, creating result nodes. Continue while either list or the carry remains. Time O(max(m, n)).

**Explanation:** Digit-by-digit addition with carry.

### 7. Implement binary search on a sorted array.

**Answer:** Maintain low and high; compute mid; if the element matches return it, if smaller search the right half, else the left half, until the range is empty. Time O(log n).

**Explanation:** Halve the range each step.

### 8. Compute the factorial of a large number that exceeds normal integer range.

**Answer:** Store the number as an array or string of digits and perform grade-school multiplication for each factor from 2 to n, handling carries. This supports arbitrarily large results.

**Explanation:** Big-integer multiplication via digit arrays.

More Oracle preparation, including the full recruitment process: https://useastra.in/campus/oracle
