# Capgemini DSA Questions with Answers

8 previously-asked dsa questions from Capgemini'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 the sum of natural numbers from 1 to n without using a loop.

**Answer:** Use the formula n*(n+1)/2, which gives the sum in O(1) time without iterating.

### 2. Check whether a given number is a palindrome.

**Answer:** Reverse the number by repeatedly extracting the last digit and rebuilding, then compare with the original. If equal it is a palindrome. Time O(number of digits).

### 3. Find the maximum and minimum element of an array in a single traversal.

**Answer:** Initialise both max and min to the first element, then update them in one pass over the remaining elements. Time O(n).

### 4. Print the multiplication table of a given number up to 10.

**Answer:** Loop i from 1 to 10 and print n*i on each line. Time O(1) for a fixed range.

### 5. Count the number of digits in a given number.

**Answer:** Loop while n > 0, dividing n by 10 each time and incrementing a counter; handle 0 as a single digit.

### 6. Check whether a given number is a power of two.

**Answer:** A positive number is a power of two if n & (n-1) equals 0, since a power of two has exactly one set bit. Time O(1).

### 7. Reverse the order of words in a given sentence.

**Answer:** Split the sentence by spaces into words, then join them in reverse order. Alternatively reverse the whole string and then reverse each word. Time O(n).

### 8. Find how many times a given element appears in an array.

**Answer:** Iterate once over the array and increment a counter whenever the element matches the target. Time O(n).

More Capgemini preparation, including the full recruitment process: https://useastra.in/campus/capgemini
