# Cyient DSA Questions with Answers

6 previously-asked dsa questions from Cyient'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. Convert a decimal number to its binary representation.

**Answer:** Repeatedly take n mod 2 to get each bit (least significant first) and do n = n / 2 until n is 0. Collect the bits and reverse them for the final binary string. Time O(log n).

**Explanation:** Repeated division by 2, collect remainders.

### 2. Find the transpose of a matrix.

**Answer:** Create a result matrix with swapped dimensions and set result[j][i] = matrix[i][j] for all i and j. For a square matrix you can swap in place across the diagonal. Time O(rows * cols).

**Explanation:** Swap rows and columns.

### 3. Check whether a singly linked list is a palindrome.

**Answer:** Find the middle with slow and fast pointers, reverse the second half, then compare it node by node with the first half. Optionally restore the list. Time O(n), space O(1).

**Explanation:** Reverse second half and compare.

### 4. Find the maximum sum of a contiguous subarray.

**Answer:** Use Kadane algorithm: keep a running current sum, reset it to the current element if it becomes smaller than the element, and track the best sum seen. Time O(n), space O(1).

**Explanation:** Kadane algorithm.

### 5. Sort an array using bubble sort.

**Answer:** Repeatedly pass through the array swapping adjacent out-of-order pairs, so the largest unsorted element settles at the end each pass. Stop early if a pass makes no swaps. Time O(n^2).

**Explanation:** Adjacent compare and swap, per pass.

### 6. Find the average of the elements in an array.

**Answer:** Sum all elements in one pass and divide by the count. Use a floating point type for the division to avoid integer truncation. Time O(n).

**Explanation:** Sum then divide by count.

More Cyient preparation, including the full recruitment process: https://useastra.in/campus/cyient
