Capgemini Coding Questions and Answers (2024 Updated)

Introduction to Capgemini Coding Questions

Capgemini Coding Questions: a global leader in consulting, technology services, and digital transformation, uses coding questions as a crucial component of their technical interviews. These questions evaluate a candidate’s problem-solving skills, logical reasoning, and proficiency in programming languages.

Importance of Coding Questions in Capgemini Interviews

Coding questions play a vital role in Capgemini interviews for several reasons. Firstly, they allow interviewers to assess the candidate’s ability to translate complex problems into efficient code. Additionally, coding questions provide insights into a candidate’s approach to problem-solving, attention to detail, and ability to work under pressure – all crucial qualities for a successful software engineer.

Preparing for Capgemini Coding Questions

To excel in Capgemini coding questions, adequate preparation is key. Here are some essential steps to help you get started:

Understanding the Coding Language Requirements

Capgemini primarily uses programming languages such as Java, C++, Python, and JavaScript. Familiarize yourself with the coding languages specified in the job requirements and ensure you have a solid understanding of their syntax, data structures, and algorithms.

Practicing Algorithmic Problem-Solving

Algorithmic problem-solving forms the core of coding questions. Dedicate time to practice various algorithmic problems, such as sorting, searching, recursion, and dynamic programming. Websites like LeetCode, HackerRank, and AtCoder offer a wide range of coding challenges to hone your skills.

Referring to Coding Resources and Tutorials

Leverage online coding resources, tutorials, and textbooks to deepen your understanding of key concepts. Explore data structures, algorithms, and programming techniques that frequently appear in coding interviews. The more you familiarize yourself with these concepts, the more confident you’ll be in tackling complex coding questions.

Capgemini Exam Pattern 2023

Number of Questions Asked

Candidates can expect to tackle three coding questions during the Capgemini coding round. These questions are carefully designed to test your coding proficiency and logical thinking.

Time Allocation

The Capgemini coding round is time-bound, with a total duration of 75 minutes. It is crucial to manage your time effectively to ensure that you can attempt all the questions within the given timeframe.

Package Offered

Capgemini offers an attractive package of 7.5 LPA (Lakhs Per Annum) to successful candidates. This competitive compensation reflects the company’s recognition of top talent and their commitment to attracting and retaining skilled professionals.

Difficulty Level

The difficulty level of the Capgemini coding round is considered high. The questions are designed to challenge candidates and assess their ability to solve complex problems using efficient and optimized code.

Preparing for the Capgemini coding round requires a solid understanding of programming concepts, data structures, algorithms, and problem-solving techniques. Practice is key to building confidence and improving your coding skills.

Capgemini Coding Questions 2024

Capgemini interview questions are designed to assess your programming skills, problem-solving abilities, and logical thinking. These questions cover various topics, including data structures, algorithms, strings, arrays, linked lists, and more. The questions are typically presented in the form of coding problems that require you to write efficient and bug-free code. In this section, we’ll discuss some popular Capgemini coding questions and provide insights on how to approach them.

Question 1

Problem Statement: Write a function that accepts a string with some “#” in it. Move all the hashes to the front of the string and return the modified string.

Input: Move#Hash#to#Front

Output: ###MoveHashtoFront


codedef move_hashes_to_front(string):
    hashes = ""
    remaining_chars = ""

    for char in string:
        if char == "#":
            hashes += "#"
            remaining_chars += char

    result = hashes + remaining_chars
    return result


  • Initialize an empty string hashes to store the hashes.
  • Initialize an empty string remaining_chars to store the non-hash characters.
  • Iterate through each character in the input string.
  • If the character is “#”, append it to the hashes string.
  • If the character is not “#”, append it to the remaining_chars string.
  • Combine the hashes and remaining_chars strings to form the final result.
  • Return the result.

The provided code iterates through each character in the string and separates the hashes from the non-hash characters. Then, it combines the two parts to form the final string with the hashes moved to the front.

Question 2

Problem Statement: Given a string with multiple characters that are repeated consecutively, reduce the size of the string using mathematical logic. Replace consecutive repeated characters with the character followed by the count of repetitions.

Input: aabbbbeeeeffggg

Output: a2b4e4f2g3


result = ""
count = 1

for i in range(1, len(string)):
if string[i] == string[i-1]:
count += 1
result += string[i-1] + str(count)
count = 1

result += string[-1] + str(count)
return result


  • Initialize an empty string result to store the reduced string.
  • Initialize a variable count to keep track of the consecutive character count, starting from 1.
  • Iterate through the characters of the input string from index 1 to the end.
  • If the current character is the same as the previous character, increment the count by 1.
  • If the current character is different from the previous character, append the previous character and its count to the result, and reset the count to 1.
  • After the loop, append the last character and its count to the result.
  • Return the result.

Question 3

Problem Statement: Traverse a matrix in a spiral format.

Input: 5 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Output: 1 2 3 4 8 12 16 20 19 18 17 13 9 5 6 7 11 15 12 14 10


spiral_traversal(matrix, rows, columns):
    top = 0
    bottom = rows - 1
    left = 0
    right = columns - 1

    result = []

    while top <= bottom and left <= right:
        for i in range(left, right + 1):
        top += 1

        for i in range(top, bottom + 1):
        right -= 1

        if top <= bottom:
            for i in range(right, left - 1, -1):
            bottom -= 1

        if left <= right:
            for i in range(bottom, top - 1, -1):
            left += 1

    return result


  • Initialize variables top, bottom, left, and right to represent the boundaries of the matrix.
  • Initialize an empty list result to store the spiral traversal elements.
  • Use a while loop to traverse the matrix in a spiral format.
  • In each iteration, append the elements from left to right for the current row (top), increment top by 1.
  • Append the elements from top to bottom for the current column (right), decrement right by 1.
  • Check if top is still less than or equal to bottom to avoid duplicating elements in certain cases.
  • If true, append the elements from right to left for the current row (bottom), decrement bottom by 1.
  • Check if left is still less than or equal to right to avoid duplicating elements in certain cases.
  • If true, append the elements from bottom to top for the current column (left), increment left by 1.
  • Finally, return the result list containing the elements in spiral order.

Question 4

Problem Statement: Given an array of integers, print the number of times each integer has occurred in the array.

Input: 10 1 2 3 3 4 1 4 5 1 2

Output: 1 occurs 3 times 2 occurs 2 times 3 occurs 2 times 4 occurs 2 times 5 occurs 1 time


codefrom collections import Counter

def count_occurrences(arr):
    counter = Counter(arr)

    for num, count in counter.items():
        print(f"{num} occurs {count} times")


  • Import the Counter class from the collections module to count the occurrences of each integer.
  • Create a counter object counter by passing the input array arr.
  • Iterate over the items of the counter.
  • Print the number (num) and its corresponding count (count) in the desired format.

Question 5

Problem Statement: Write a function to solve the following equation a3 + a2b + 2a2b + 2ab2 + ab2 + b3. Write a program to accept three values in order of a, b, and c, and get the result of the above equation.


codedef equation_result(a, b, c):
    result = (a ** 3) + (a ** 2 * b) + (2 * a ** 2 * b) + (2 * a * b ** 2) + (a * b ** 2) + (b ** 3)
    return result


  • Compute the equation a^3 + a^2b + 2a^2b + 2ab^2 + ab^2 + b^3 using the provided values a, b, and c.
  • Return the result.

Question 6

Problem Statement: Given the number of dealerships and the total number of cars and bikes in each dealership, calculate how many tires would be there in each dealership.

Input: 3 4 2 4 0 1 2

Output: 20 16 8


result = []

for cars, bikes in dealerships:
total_tyres = (cars * 4) + (bikes * 2)

return result


  • Iterate over the dealerships list, which contains pairs of car and bike counts.
  • For each dealership, calculate the total number of tires by multiplying the car count by 4 and the bike count by 2.
  • Append the total number of tires for each dealership to the result list.
  • Return the result list containing the total number of tires for each dealership.

Remember, these are just one of the possible approaches to solving the given questions. There might be alternative solutions or optimizations based on specific requirements or constraints.

Tips for Solving Capgemini Coding Questions Effectively

Solving coding questions effectively requires a structured approach and attention to detail. Consider the following tips to enhance your problem-solving skills:

Analyzing the Problem Statement

Before jumping into coding, take the time to fully understand the problem statement. Identify the inputs, outputs, and any constraints. Break the problem down into smaller parts, making it easier to devise an effective solution.

Breaking Down the Problem into Smaller Parts

Complex coding problems can often be solved by breaking them down into smaller, more manageable parts. This approach allows you to focus on solving individual components and then combine them to form a complete solution.

Writing Efficient and Optimized Code

Efficiency is crucial when it comes to coding questions. Strive to write code that solves the problem optimally, considering time and space complexity. Use appropriate data structures and algorithms to ensure your solution performs well even for large input sizes.

Testing and Debugging the Code

After implementing your solution, thoroughly test it against various test cases. Check for logical errors, edge cases, and boundary conditions. Debug and refine your code until it produces the expected results consistently.

Common Mistakes to Avoid in Capgemini Coding Questions

To increase your chances of success, be mindful of the following common mistakes:

Ignoring Time and Space Complexity

Failing to consider the time and space complexity of your solution can lead to inefficient code. Strive for solutions with optimal time and space complexity to demonstrate your proficiency.

Failing to Handle Edge Cases

Neglecting to account for edge cases can result in incorrect or incomplete solutions. Consider scenarios such as empty inputs, negative numbers, or large input sizes when designing your code.

Not Using Appropriate Data Structures

Choosing the right data structures can significantly impact the efficiency of your solution. Understand the strengths and weaknesses of different data structures and select the most suitable one for the problem at hand.


Mastering Capgemini coding questions requires a combination of technical knowledge, problem-solving skills, and effective time management. By understanding the importance of coding questions, preparing diligently, and implementing the strategies discussed, you can enhance your chances of success in Capgemini interviews.