# Intuit DSA Questions with Answers

6 previously-asked dsa questions from Intuit'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. Given a sorted array, find two numbers that add up to a target using two pointers.

**Answer:** Place one pointer at the start and one at the end. If the sum is too large move the right pointer left, if too small move the left pointer right, until they match the target or cross. Time O(n), space O(1).

**Explanation:** Two-pointer inward scan on a sorted array.

### 2. Validate whether a binary tree is a valid binary search tree.

**Answer:** Recurse carrying a valid (min, max) range for each node; the node value must lie strictly within it, and children get tightened ranges. An inorder traversal that stays strictly increasing also works. Time O(n).

**Explanation:** Range-bounded recursion or inorder monotonic check.

### 3. Count the number of islands in a 2D grid of land and water.

**Answer:** Scan the grid; on each unvisited land cell, run DFS or BFS to flood-fill all connected land and increment the island count. Time O(rows * cols).

**Explanation:** Flood fill each connected land region.

### 4. Find the kth smallest element in a binary search tree.

**Answer:** Do an inorder traversal (which yields sorted order) and return the kth visited node. An iterative inorder with a stack lets you stop early at the kth element. Time O(h + k).

**Explanation:** Inorder traversal, stop at the kth node.

### 5. Design and implement an LRU cache with O(1) get and put.

**Answer:** Combine a hash map (key to node) with a doubly linked list ordered by recency. get and put move the node to the front; when capacity is exceeded, evict the tail node. Both operations are O(1).

**Explanation:** Hash map plus doubly linked list.

### 6. Find the longest palindromic substring in a string.

**Answer:** Expand around each centre (2n-1 centres) tracking the longest palindrome found, in O(n^2) time and O(1) space. Manacher algorithm solves it in O(n).

**Explanation:** Expand around centre, or Manacher for O(n).

More Intuit preparation, including the full recruitment process: https://useastra.in/campus/intuit
