# LTIMindtree DSA Questions with Answers

6 previously-asked dsa questions from LTIMindtree'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 pairs in an array whose difference equals a given value k.

**Answer:** Store elements in a hash set. For each element x, check whether x + k exists in the set; if so, that pair has difference k. Handle duplicates carefully. Time O(n).

**Explanation:** Hash set lookup for x + k.

### 2. Reverse a string using recursion.

**Answer:** Base case: an empty or single-character string returns itself. Otherwise return reverse of the substring from index 1, with the first character appended at the end. Time O(n), with O(n) recursion depth.

**Explanation:** Recurse on the tail, append the head last.

### 3. Detect whether a linked list contains a cycle.

**Answer:** Use Floyd cycle detection with slow and fast pointers. If they meet, a cycle exists; if fast reaches null, there is none. Time O(n), space O(1).

**Explanation:** Floyd tortoise and hare.

### 4. Find the kth largest element in an array.

**Answer:** Use a min-heap of size k: push elements and pop when the size exceeds k, so the heap top is the kth largest. Time O(n log k). Quickselect gives average O(n).

**Explanation:** Min-heap of size k, or quickselect.

### 5. Print a diamond star pattern of a given height.

**Answer:** Print an upper pyramid with increasing stars and leading spaces, then a lower inverted pyramid with decreasing stars. Use nested loops to manage spaces and stars per row. Time O(n^2).

**Explanation:** Two pyramids with spacing.

### 6. Find the frequency of the most repeated element in an array.

**Answer:** Build a frequency map in one pass, then take the maximum count. Return that count (and optionally the element). Time O(n), space O(n).

**Explanation:** Frequency map then take the maximum.

More LTIMindtree preparation, including the full recruitment process: https://useastra.in/campus/ltimindtree
