Cracking the Capgemini interview? Pseudocode questions can trip up even the best candidates. This article helps! We understand the pressure of technical interviews, and deciphering pseudocode can add extra stress.

This guide provides sample Capgemini pseudocode questions with clear answers. Learn how to solve these problems and confidently showcase your coding skills.

## What to Expect in Capgemini Pseudocode Interviews

Cracking the Capgemini interview process often involves a round where you’ll be tested on your ability to write pseudocode. This section will prepare you for what to expect in this stage.

### Format of Pseudocode Interview Questions (Written or Verbal)

Capgemini’s pseudocode interview questions can be presented in two formats: written or verbal.

**Written format:**You might be given a problem and asked to write the pseudocode solution on paper or a coding platform.**Verbal format:**The interviewer might describe a problem and ask you to explain your thought process and the pseudocode steps you would take to solve it.

In both cases, strong communication skills are crucial. Even for written tests, be prepared to explain your approach if needed.

### Types of Problems Using Pseudocode

Capgemini uses pseudocode to assess your understanding of fundamental programming concepts. Here’s a breakdown of the problems you might encounter:

**Loops (for, while):** Expect questions where you need to use loops to iterate through data sets, perform repetitive tasks a certain number of times, or continue execution until a specific condition is met.

**Conditional statements (if, else):** You might be asked to write pseudocode that checks conditions and executes different code blocks based on those conditions. These questions test your ability to write logical branching code.

**Calculations:** Some problems will involve calculations using variables and basic mathematical operators like addition, subtraction, multiplication, and division.

**Functions (optional): **While less common, Capgemini might introduce basic function concepts in pseudocode questions. Here, you might be asked to break down a problem into smaller, reusable functions.

### Level of Difficulty of Pseudocode Questions

The difficulty of Capgemini’s pseudocode questions can vary depending on the specific role you’re applying for. Here’s a general idea:

**Beginner:**These questions focus on basic programming concepts like simple loops, conditional statements, and calculations with a few variables.**Intermediate:**You might encounter problems that involve nested loops, more complex conditional statements (if-else if), and working with arrays or lists.**Advanced (less common):**For senior roles, Capgemini might introduce problems requiring functions or basic data structures like stacks or queues in pseudocode.

**Pro tip:** When unsure about the difficulty level for your specific role, research online forums or consult with someone familiar with the Capgemini interview process for that position.

Now that you know what to expect, dive into common Capgemini pseudocode questions with answers to practise your skills.

## Common Capgemini Pseudocode Questions (with Answers)

Get a head start on your interview prep! Here are some typical Capgemini pseudocode questions along with solutions.

### Section A: Capgemini PseudoCode Beginner Level Questions

**1) Write a pseudocode to find the sum of all even numbers from 1 to 100.**

text

INITIALIZE sum = 0

FOR i = 2 TO 100 STEP 2

sum = sum + i

ENDFOR

PRINT sum

Explanation:

- We initialise a variable sum to 0 to keep track of the running total.
- We use a for loop to iterate from 2 to 100, incrementing by 2 each time to only consider even numbers.
- Inside the loop, we add the current value of i (an even number) to the sum variable.
- After the loop completes, we print the final value of sum, which will be the sum of all even numbers from 1 to 100.

**2) Write a pseudocode to find the factorial of a given number.**

text

FUNCTION factorial(n)

IF n = 0 THEN

RETURN 1

ELSE

RETURN n * factorial(n-1)

ENDIF

ENDFUNCTION

INITIALIZE num

READ num

result = factorial(num)

PRINT result

Explanation:

- We define a function called factorial that takes a single parameter n.
- Inside the function, we use an if statement to check if n is equal to 0.
- If n is 0, we return 1 (as per the factorial definition).
- If n is not 0, we recursively call the factorial function with n-1 and multiply the result by n.
- In the main part of the pseudocode, we prompt the user to enter a number, store it in the num variable.
- We call the factorial function with num as the argument and store the result in the result variable.
- Finally, we print the result.

**3) Write a pseudocode to check if a given number is prime.**

text

FUNCTION isPrime(n)

IF n <= 1 THEN

RETURN false

ENDIF

FOR i = 2 TO sqrt(n)

IF n mod i = 0 THEN

RETURN false

ENDIF

ENDFOR

RETURN true

ENDFUNCTION

INITIALIZE num

READ num

result = isPrime(num)

PRINT result

Explanation:

- We define a function called isPrime that takes a single parameter n.
- Inside the function, we first check if n is less than or equal to 1. If so, we return false because 1 and negative numbers are not considered prime.
- We then use a for loop to iterate from 2 to the square root of n.
- For each iteration, we check if n is divisible by the current value of i using the modulo operator (mod). If it is, we return false because n has a factor other than 1 and itself.
- If the loop completes without finding any factors, we return true because n is prime.
- In the main part of the pseudocode, we prompt the user to enter a number, store it in the num variable.
- We call the isPrime function with num as the argument and store the result (either true or false) in the result variable.
- Finally, we print the result.

**4) Write a pseudocode to find the maximum and minimum values in a given array.**

text

FUNCTION findMinMax(arr, size)

min = arr[0]

max = arr[0]

FOR i = 1 TO size-1

IF arr[i] < min THEN

min = arr[i]

ENDIF

IF arr[i] > max THEN

max = arr[i]

ENDIF

ENDFOR

RETURN min, max

ENDFUNCTION

INITIALIZE size

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

minVal, maxVal = findMinMax(arr, size)

PRINT “Minimum value:”, minVal

PRINT “Maximum value:”, maxVal

Explanation:

- We define a function called findMinMax that takes two parameters: arr (the array) and size (the size of the array).
- Inside the function, we initialise min and max variables with the first element of the array (arr).
- We use a for loop to iterate from index 1 to size-1 (the last index).
- For each iteration, we check if the current element (arr[i]) is less than the current min value. If so, we update min with the current element.
- We also check if the current element is greater than the current max value. If so, we update max with the current element.
- After the loop completes, we return both min and max values.
- In the main part of the pseudocode, we prompt the user to enter the size of the array and store it in the size variable.
- We declare an array arr with the specified size.
- We use a for loop to prompt the user to enter each element of the array and store it in the corresponding index of arr.
- We call the findMinMax function with arr and size as arguments and store the returned min and max values in minVal and maxVal respectively.
- Finally, we print the minimum and maximum values.

**5) Write a pseudocode to reverse a given string.**

text

FUNCTION reverseString(str)

DECLARE reversed = “”

FOR i = length(str)-1 TO 0 STEP -1

reversed = reversed + str[i]

ENDFOR

RETURN reversed

ENDFUNCTION

INITIALIZE str

READ str

result = reverseString(str)

PRINT result

Explanation:

- We define a function called reverseString that takes a single parameter str (the input string).
- Inside the function, we initialise an empty string called reversed to store the reversed string.
- We use a for loop to iterate from the last index of str (length of str – 1) to 0, decrementing by 1 each time.
- For each iteration, we append the character at the current index (str[i]) to the reversed string.
- After the loop completes, we return the reversed string.
- In the main part of the pseudocode, we prompt the user to enter a string and store it in the str variable.
- We call the reverseString function with str as the argument and store the returned reversed string in the result variable.
- Finally, we print the result.

### Section B: Capgemini Pseudo Code Intermediate Level Questions

**6) Write a pseudocode to find the second largest element in a given array.**

text

FUNCTION findSecondLargest(arr, size)

largest = arr[0]

secondLargest = -infinity

FOR i = 1 TO size-1

IF arr[i] > largest THEN

secondLargest = largest

largest = arr[i]

ELSE IF arr[i] > secondLargest AND arr[i] != largest THEN

secondLargest = arr[i]

ENDIF

ENDFOR

RETURN secondLargest

ENDFUNCTION

INITIALIZE size

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

result = findSecondLargest(arr, size)

PRINT result

Explanation:

- We define a function called findSecondLargest that takes two parameters: arr (the array) and size (the size of the array).
- Inside the function, we initialise largest with the first element of the array (arr) and secondLargest with negative infinity (-infinity).
- We use a for loop to iterate from index 1 to size-1 (the last index).
- For each iteration, we check if the current element (arr[i]) is greater than the current largest value. If so, we update secondLargest with the current largest value and then update largest with the current element.
- We also check if the current element is greater than the current secondLargest value and is not equal to the current largest value. If so, we update secondLargest with the current element.
- After the loop completes, we return the secondLargest value.
- In the main part of the pseudocode, we prompt the user to enter the size of the array and store it in the size variable.
- We declare an array arr with the specified size.
- We use a for loop to prompt the user to enter each element of the array and store it in the corresponding index of arr.
- We call the findSecondLargest function with arr and size as arguments and store the returned second largest value in the result variable.
- Finally, we print the result.

**7) Write a pseudocode to find the common elements between two sorted arrays.**

text

FUNCTION findCommonElements(arr1, size1, arr2, size2)

DECLARE commonElements = []

i = 0

j = 0

WHILE i < size1 AND j < size2

IF arr1[i] == arr2[j] THEN

commonElements.add(arr1[i])

i++

j++

ELSE IF arr1[i] < arr2[j] THEN

i++

ELSE

j++

ENDIF

ENDWHILE

RETURN commonElements

ENDFUNCTION

INITIALIZE size1, size2

READ size1, size2

DECLARE arr1[size1], arr2[size2]

FOR i = 0 TO size1-1

READ arr1[i]

ENDFOR

FOR j = 0 TO size2-1

READ arr2[j]

ENDFOR

result = findCommonElements(arr1, size1, arr2, size2)

PRINT result

Explanation:

- We define a function called findCommonElements that takes four parameters: arr1 (the first array), size1 (the size of the first array), arr2 (the second array), and size2 (the size of the second array).
- Inside the function, we initialise an empty array called commonElements to store the common elements between the two arrays.
- We use two pointers, i and j, to traverse arr1 and arr2 respectively.
- We use a while loop that continues as long as both i is less than size1 and j is less than size2.
- Inside the loop, we compare the elements at indices i and j in arr1 and arr2 respectively.
- If the elements are equal, we add the element to commonElements, increment both i and j by 1.
- If the element at index i in arr1 is less than the element at index j in arr2, we increment i by 1.
- If the element at index j in arr2 is less than the element at index i in arr1, we increment j by 1.
- After the loop completes, we return the commonElements array.
- In the main part of the pseudocode, we prompt the user to enter the sizes of both arrays and store them in the size1 and size2 variables respectively.
- We declare two arrays arr1 and arr2 with the specified sizes.
- We use two separate for loops to prompt the user to enter each element of arr1 and arr2 respectively and store them in the corresponding indices.
- We call the findCommonElements function with arr1, size1, arr2, and size2 as arguments and store the returned array of common elements in the result variable.
- Finally, we print the result.

**8) Write a pseudocode to implement a simple calculator using switch-case statements.**

text

FUNCTION calculate(num1, num2, operator)

SWITCH operator

CASE ‘+’

RETURN num1 + num2

CASE ‘-‘

RETURN num1 – num2

CASE ‘*’

RETURN num1 * num2

CASE ‘/’

IF num2 == 0 THEN

RETURN “Error: Division by zero”

ELSE

RETURN num1 / num2

ENDIF

DEFAULT

RETURN “Error: Invalid operator”

ENDSWITCH

ENDFUNCTION

INITIALIZE num1, num2, op

READ num1, num2, op

result = calculate(num1, num2, op)

PRINT result

**Explanation:**

- We define a function called calculate that takes three parameters: num1 (the first number), num2 (the second number), and operator (the arithmetic operator).
- Inside the function, we use a switch statement to check the value of the operator.
- For each case (+, -, *, /), we perform the corresponding arithmetic operation on num1 and num2.
- For the division case (/), we first check if num2 is equal to 0. If so, we return an error message “Error: Division by zero”.
- If num2 is not 0, we perform the division operation and return the result.
- If the operator does not match any of the cases, we return an error message “Error: Invalid operator”.
- In the main part of the pseudocode, we prompt the user to enter two numbers (num1 and num2) and an operator (op), and store them in the respective variables.
- We call the calculate function with num1, num2, and op as arguments and store the returned result in the result variable.
- Finally, we print the result.

**9) Write a pseudocode to implement a linear search algorithm.**

text

FUNCTION linearSearch(arr, size, target)

FOR i = 0 TO size-1

IF arr[i] == target THEN

RETURN i

ENDIF

ENDFOR

RETURN -1

ENDFUNCTION

INITIALIZE size, target

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

READ target

index = linearSearch(arr, size, target)

IF index == -1 THEN

PRINT “Element not found”

ELSE

PRINT “Element found at index:”, index

ENDIF

Explanation:

- We define a function called linearSearch that takes three parameters: arr (the array), size (the size of the array), and target (the element to search for).
- Inside the function, we use a for loop to iterate through each element of the array from index 0 to size-1.
- For each iteration, we check if the current element (arr[i]) is equal to the target element.
- If the elements are equal, we return the current index i.
- If the loop completes without finding the target element, we return -1 to indicate that the element was not found.
- In the main part of the pseudocode, we prompt the user to enter the size of the array and store it in the size variable.
- We declare an array arr with the specified size.
- We use a for loop to prompt the user to enter each element of the array and store it in the corresponding index of arr.
- We prompt the user to enter the target element to search for.
- We call the linearSearch function with arr, size, and target as arguments and store the returned index in the index variable.
- We use an if statement to check if the index is equal to -1 (indicating that the element was not found).
- If the element is not found, we print “Element not found”.
- If the element is found, we print “Element found at index:” followed by the index value.

**10) Write a pseudocode to find the maximum product of two integers in an array.**

text

FUNCTION findMaxProduct(arr, size)

IF size < 2 THEN

RETURN “Error: Array must contain at least two elements”

ENDIF

max1 = -infinity

max2 = -infinity

FOR i = 0 TO size-1

IF arr[i] > max1 THEN

max2 = max1

max1 = arr[i]

ELSE IF arr[i] > max2 THEN

max2 = arr[i]

ENDIF

ENDFOR

RETURN max1 * max2

ENDFUNCTION

INITIALIZE size

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

result = findMaxProduct(arr, size)

PRINT result

**Explanation:**

- We define a function called findMaxProduct that takes two parameters: arr (the array) and size (the size of the array).
- Inside the function, we first check if the size of the array is less than 2. If so, we return an error message indicating that the array must contain at least two elements.
- We initialise two variables, max1 and max2, to negative infinity to keep track of the two largest numbers in the array.
- We use a for loop to iterate through each element of the array from index 0 to size-1.
- For each iteration, we check if the current element (arr[i]) is greater than max1. If it is, we update max2 to be max1 (the previous largest) and then update max1 to the current element.
- If the current element is not greater than max1 but is greater than max2, we update max2 with the current element.
- After the loop completes, we return the product of max1 and max2, which gives the maximum product of any two integers in the array.
- We declare an array arr with the specified size.
- We call the findMaxProduct function with arr and size as arguments and store the returned product in the result variable.
- Finally, we print the result.

### Section C: Capgemini Pseudo Code Advanced Level Questions

**11) Write a pseudocode to implement a recursive function for calculating the Fibonacci sequence.**

text

FUNCTION fibonacci(n)

IF n <= 0 THEN

RETURN 0

ELSE IF n = 1 THEN

RETURN 1

ELSE

RETURN fibonacci(n – 1) + fibonacci(n – 2)

ENDIF

ENDFUNCTION

INITIALIZE num

READ num

result = fibonacci(num)

PRINT result

**Explanation:**

- We define a recursive function called fibonacci that calculates the nth Fibonacci number.
- The base cases are defined: if n is less than or equal to 0, the function returns 0; if n equals 1, it returns 1.
- For any other value of n, the function calls itself recursively to calculate the sum of the two preceding Fibonacci numbers: fibonacci(n – 1) and fibonacci(n – 2).
- In the main part of the pseudocode, we prompt the user to enter a number and store it in num.
- We call the fibonacci function with num and store the result.
- Finally, we print the result.

**12) Write a pseudocode to implement the Merge Sort algorithm.**

text

FUNCTION mergeSort(arr)

IF length(arr) <= 1 THEN

RETURN arr

ENDIF

mid = length(arr) / 2

left = mergeSort(arr[0:mid])

right = mergeSort(arr[mid:length(arr)])

RETURN merge(left, right)

END FUNCTION

FUNCTION merge(left, right)

DECLARE result = []

i = 0

j = 0

WHILE i < length(left) AND j < length(right)

IF left[i] < right[j] THEN

result.add(left[i])

i++

ELSE

result.add(right[j])

j++

ENDIF

ENDWHILE

WHILE i < length(left)

result.add(left[i])

i++

ENDWHILE

WHILE j < length(right)

result.add(right[j])

j++

ENDWHILE

RETURN result

END FUNCTION

INITIALIZE size

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

sortedArray = mergeSort(arr)

PRINT sortedArray

**Explanation:**

- We define a function called mergeSort that takes an array as input and recursively sorts it.
- If the length of the array is less than or equal to 1, it is already sorted, so we return it.
- We find the middle index of the array and split it into two halves: left and right.
- We recursively call mergeSort on both halves and then merge the sorted halves using the merge function.
- The merge function takes two sorted arrays as input and merges them into a single sorted array.
- We use two pointers, i and j, to traverse the left and right arrays respectively.
- We compare the elements pointed to by i and j and add the smaller one to the result array, incrementing the respective pointer.
- After one of the arrays is fully traversed, we add the remaining elements of the other array to result.
- Finally, we return the merged result array.
- In the main part of the pseudocode, we prompt the user to enter the size of the array and the elements of the array.
- We call the mergeSort function with the array and store the sorted array in sortedArray.
- Finally, we print the sorted array.

**13) Write a pseudocode to implement a binary search algorithm.**

text

FUNCTION binarySearch(arr, size, target)

low = 0

high = size – 1

WHILE low <= high

mid = (low + high) / 2

IF arr[mid] == target THEN

RETURN mid

ELSE IF arr[mid] < target THEN

low = mid + 1

ELSE

high = mid – 1

ENDIF

ENDWHILE

RETURN -1

ENDFUNCTION

INITIALIZE size, target

READ size

DECLARE arr[size]

FOR i = 0 TO size-1

READ arr[i]

ENDFOR

READ target

index = binarySearch(arr, size, target)

IF index == -1 THEN

PRINT “Element not found”

ELSE

PRINT “Element found at index:”, index

ENDIF

Explanation:

- We define a function called binarySearch that takes three parameters: arr (the sorted array), size (the size of the array), and target (the element to search for).
- We initialise two pointers, low and high, to represent the current search range.
- We use a while loop that continues as long as low is less than or equal to high.
- Inside the loop, we calculate the midpoint index (mid) of the current search range.
- We compare the element at mid with the target:
- If they are equal, we return mid.
- If the element at mid is less than the target, we adjust the low pointer to mid + 1 to search the right half.
- If the element at mid is greater than the target, we adjust the high pointer to mid – 1 to search the left half.
- If the loop completes without finding the target, we return -1.
- In the main part of the pseudocode, we prompt the user to enter the size of the array and the elements of the array.
- We read the target element to search for.
- We call the binarySearch function with arr, size, and target as arguments and store the returned index in index.
- We check if the index is -1 (not found) or print the found index.

**14) Write a pseudocode to implement a simple linked list with insertion and display functions.**

text

CLASS Node

DECLARE data

DECLARE next

FUNCTION insert(head, value)

DECLARE newNode = new Node

newNode.data = value

newNode.next = NULL

IF head == NULL THEN

RETURN newNode

ENDIF

current = head

WHILE current.next != NULL

current = current.next

ENDWHILE

current.next = newNode

RETURN head

END FUNCTION

FUNCTION display(head)

current = head

WHILE current != NULL

PRINT current.data

current = current.next

ENDWHILE

END FUNCTION

INITIALIZE head = NULL

INITIALIZE value

WHILE TRUE

READ value

IF value == -1 THEN

BREAK

ENDIF

head = insert(head, value)

ENDWHILE

display(head)

Explanation:

- We define a class called Node with two attributes: data (to store the value) and next (to point to the next node).
- The insert function takes the head of the linked list and a value to insert.
- We create a new node and assign the value to its data attribute.
- If the list is empty (head is NULL), we return the new node as the new head.
- If the list is not empty, we traverse to the end of the list and set the next of the last node to the new node.
- The display function takes the head of the linked list and prints the values of each node until it reaches the end (NULL).
- In the main part of the pseudocode, we initialize head to NULL and prompt the user to enter values to insert into the linked list.
- The loop continues until the user enters -1, which indicates they want to stop inserting values.
- Finally, we call the display function to print the values of the linked list.

**15) Write a pseudocode to implement depth-first search (DFS) for a graph.**

text

FUNCTION DFS(graph, start, visited)

PRINT start

visited.add(start)

FOR each neighbor in graph[start]

IF neighbor NOT IN visited THEN

DFS(graph, neighbor, visited)

ENDIF

ENDFOR

END FUNCTION

INITIALIZE graph = {

“A”: [“B”, “C”],

“B”: [“A”, “D”, “E”],

“C”: [“A”, “F”],

“D”: [“B”],

“E”: [“B”, “F”],

“F”: [“C”, “E”]

}

INITIALIZE visited = []

INITIALIZE startNode = “A”

DFS(graph, startNode, visited)

Explanation:

- We define a function called DFS that takes three parameters: graph (the adjacency list representation of the graph), start (the starting node), and visited (a set to keep track of visited nodes).
- We print the current node (start) and add it to the visited set.
- We iterate through each neighbor of the current node in the graph.
- If a neighbor has not been visited, we recursively call DFS for that neighbor.
- In the main part of the pseudocode, we define a sample graph using an adjacency list.
- We initialise an empty set called visited to keep track of nodes that have been visited.
- We specify the starting node (startNode) and call the DFS function with the graph, starting node, and visited set.

Feeling confident? Check out the next section for tips to tackle any pseudocode question they throw your way.

## Tips for Answering Capgemini Pseudocode Questions

Acing the pseudocode section of your Capgemini interview is crucial. Here are five key strategies to help you conquer those questions:

### 1) Focus on Understanding the Problem:

- Read the question thoroughly. Don’t rush in. Take a moment to grasp what the problem asks you to solve.
- Identify key elements. Look for keywords like “find,” “calculate,” or “print.” These indicate the desired outcome.
- Pay attention to any specific details mentioned, like input values or constraints.

### 2) Break Down the Problem:

- Don’t try to write the entire solution at once.
- Divide the problem into smaller, more manageable steps. Think of it like building blocks.
- Each step should contribute to the overall solution.

### 3) Write Clear and Concise Pseudocode:

- Use proper indentation. This visually shows the hierarchy of your code and makes it easier to read.
- Add comments to explain complex parts of your code. This helps both you and the interviewer understand the logic.
- Choose meaningful variable names. Don’t use single letters like “x” or “y.” Descriptive names like “totalSum” or “customerName” make the code clearer.

### 4) Test Your Solution:

- Don’t write code and hope it works. Walk through your pseudocode with sample inputs.
- Pick a few different test cases that cover various scenarios.
- Trace the execution of your code with each test case. This helps identify any errors or unexpected behaviour.

### 5) Communicate Effectively:

- Even if the question doesn’t ask for a verbal explanation, explain your thought process to the interviewer.
- Talk about how you approached the problem and why you chose specific steps.
- This shows your problem-solving skills and ability to communicate technical concepts.

## Conclusion

This article gave you a taste of Capgemini’s pseudocode interview questions. By understanding these questions and how to answer them, you’ll be well on your way to success in your interview.

Remember, practice makes perfect! Use our iScalePro tool to write your own pseudocode and test your skills. iScalePro will show you step-by-step how to solve problems just like you’d see in a real interview.

Don’t wait, try iScalePro today and land your dream job at Capgemini!