# Accenture DSA Questions with Answers

8 previously-asked dsa questions from Accenture'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. Write a program to reverse a string without using any built-in reverse function.

**Answer:** Use two pointers, one at the start and one at the end, swap the characters and move the pointers towards each other until they meet. Time O(n), space O(1).

### 2. Write a program to check whether a given number is prime.

**Answer:** Handle numbers <= 1 as not prime. Then check divisibility from 2 up to the square root of n; if any divides n it is not prime, otherwise it is prime. Time O(sqrt(n)).

### 3. Find the second largest element in an array in a single pass.

**Answer:** Track two variables, largest and secondLargest, initialised to negative infinity. For each element update largest first, pushing the old largest into secondLargest when a bigger value appears. Time O(n).

### 4. Print the Fibonacci series up to n terms.

**Answer:** Keep two variables a=0 and b=1, print a, then repeatedly compute next = a+b and shift a=b, b=next for n terms. Time O(n), space O(1).

### 5. Check whether a given string is a palindrome.

**Answer:** Use two pointers from both ends comparing characters; if all match it is a palindrome. Time O(n), space O(1).

### 6. Count the number of vowels in a given string.

**Answer:** Iterate over each character and increment a counter when the lowercased character is one of a, e, i, o, u. Time O(n).

### 7. Find the factorial of a number using both iterative and recursive approaches.

**Answer:** Iterative: multiply a running product from 1 to n. Recursive: factorial(n) = n * factorial(n-1) with base case factorial(0)=1. Watch for overflow on large n.

### 8. Remove duplicate characters from a string while preserving order.

**Answer:** Maintain a boolean seen array or hash set of size 256; append a character to the result only the first time it is seen. Time O(n).

More Accenture preparation, including the full recruitment process: https://useastra.in/campus/accenture
