# Persistent Systems DSA Questions with Answers

6 previously-asked dsa questions from Persistent Systems'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. Reverse a linked list in groups of size k.

**Answer:** Reverse the first k nodes, then recursively (or iteratively) reverse the next groups and link them. If fewer than k nodes remain, leave them as is or reverse per the variant asked. Time O(n).

**Explanation:** Reverse k nodes at a time, then link groups.

### 2. Find the lowest common ancestor (LCA) of two nodes in a binary tree.

**Answer:** Recurse: if the current node is null or one of the targets, return it. Recurse left and right; if both sides return non-null, the current node is the LCA, otherwise return the non-null side. Time O(n).

**Explanation:** Recursive LCA on both subtrees.

### 3. Detect and remove a loop in a linked list.

**Answer:** Use Floyd cycle detection to find the meeting point, then find the loop start by moving one pointer to the head and advancing both one step until they meet; set the last node next to null. Time O(n).

**Explanation:** Floyd detection then break the loop.

### 4. Generate all subsets of a given set.

**Answer:** Use backtracking or iterate over all bitmasks from 0 to 2 to the n minus 1, including an element when its bit is set. There are 2 to the n subsets. Time O(n * 2 to the n).

**Explanation:** Backtracking or bitmask enumeration.

### 5. Search for a target in a rotated sorted array.

**Answer:** Use a modified binary search: at each step one half is sorted. Decide which half is sorted, check whether the target lies within it, and narrow the range accordingly. Time O(log n).

**Explanation:** Modified binary search on the sorted half.

### 6. Merge k sorted linked lists into one sorted list.

**Answer:** Use a min-heap holding the current head of each list; repeatedly pop the smallest, append it, and push its next node. Alternatively merge lists pairwise. Time O(N log k) for N total nodes.

**Explanation:** Min-heap of list heads, or pairwise merge.

More Persistent Systems preparation, including the full recruitment process: https://useastra.in/campus/persistent
