Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

# Capgemini Exam Pattern | Coding Questions Pattern

Last Updated on October 3, 2022 by Ria Pathak

In this Article, we’ll be discussing the Capgemini Exam Pattern, Capgemini Coding Questions has been included as a new round in Capgemini selection process for 2023 graduates. This round will be conducted through CoCubes, containing 3 coding questions and you will have a total of 60 mins to solve these 3 coding questions. This round has been added to check the candidates programming, logical and problem solving techniques. Below we have given some previous year sample based questions for Capgemini Coding Round, make sure you practice all of them.

### Details for Capgemini Coding Round

Coding Details Details
Number of Questions 3
Time available 75 mins
Package offered 7.5LPA
Difficulty high

Capgemini has started asking Coding Questions, but it is asked in a special hiring where the package being offered is more than the normal hiring. The package offered for this post is 7.5LPA, and since the package being offered is comparatively higher than the normal hiring process, the selection process and test difficulties level are also higher than normal.

Practice makes a coder perfect, so don’t miss to check Competitive Coding Problems created by expert mentors at Prepbytes.

### Top 10 Capgemini Exam Pattern-Coding Questions

1. Problem Statement –
Write the code to traverse a matrix in a spiral format.

Sample Input

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

Solution:

```import java.util.*;
public class Solution
{
public static List<Integer> solve(int [][]matrix,int row,int col)
{
List<Integer> res=new ArrayList<Integer>();
boolean[][] temp=new boolean[row][col];
int []arr1={0,1,0,-1};
int []arr2={1,0,-1,0};
int di=0,r=0,c=0;
for(int i=0;i<row*col;i++)
{
temp[r][c]=true;
int count1=r+arr1[di];
int count2=c+arr2[di];
if(count1>=0 && row>count1 && count2>=0 && col>count2 && !temp[count1][count2]){
r=count1;
c=count2;
}
else
{
di=(di+1)%4;
r+=arr1[di];
c+=arr2[di];
}
}
return res;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
int matrix[][]=new int[m][n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
matrix[i][j]=sc.nextInt();
}
System.out.println(solve(matrix,m,n));
}
}
```

2. Problem Statement –
You’re given an array of integers, print the number of times each integer has occurred in the array.

Example

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 times

Solution:

```import java.util.Scanner;
public class ArrayFrequency
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int array[] = new int[n];       // taking value of integer
int count = 0;
int k = 0;
for(int i=0; i<n; i++)
{
array[i] = sc.nextInt();    //elements of array
}
//step - 1
int newarray[] = new int[n];
for(int i=0; i<n; i++)
{
count = 0;
for(int j=0; j<=i; j++)
{
if(array[i]==array[j])
{
count++;
}
}
if(count == 1)
{
newarray[k] = array[i];
k++;
}
}
//step 2;
for(int i=0; i<k; i++)
{
count  = 0;
for(int j=0; j<n; j++)
{
if(newarray[i] == array[j])
{
count++;
}
}
System.out.printf("%d occurs %d times\n",newarray[i],count);
}
}
}
```

3. Problem Statement –
A function is there which tells how many dealerships there are and the total number of cars in each dealership.
Your job is to calculate how many tyres would be there in each dealership.

Input
3
4 2
4 0
1 2

Output
20
16
8

There are total 3 dealerships
dealerships1 contains 4 cars and 2 bikes
dealerships2 contains 4 cars and 0 bikes
dealerships3 contains 1 cars and 2 bikes
Total number of tyres in dealerships1 is (4 x 4) + (2 x 2) = 20
Total number of tyres in dealerships2 is (4 x 4) + (0 x 2) = 16
Total number of tyres in dealerships3 is (1 x 4) + (2 x 2) = 8

Solution:

```import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int dealership=sc.nextInt();
while(dealership-->0)
{
int cars=sc.nextInt();
int bikes=sc.nextInt();
System.out.println(cars*4+bikes*2);
}
}
}
```

4. Problem Statement
Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike, he took exactly n steps. For every step he took, he noted if it was an uphill or a downhill step. Gary’s hikes start and end at sea level. We define the following terms:

• A mountain is a non-empty sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.
• A valley is a non-empty sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level.
Given Gary’s sequence of up and down steps during his last hike, find and print the number of valleys he walked through.
Input Format
The first line contains an integer, , denoting the number of steps in Gary’s hike.
The second line contains a single string of characters. Each character belongs to {U, D} (where U indicates a step up and D indicates a step down), and the i(th) cin the string describes Gary’s i(th) step during the hike.

Constraints

• 2 <= N <= 106

Output Format
Print a single integer denoting the number of valleys Gary walked through during his hike.

Sample Input
8
UDDDUDUU

Sample Output
1

Explanation
If we represent as sea level, a step up as / , and a step down as \ , Gary’s hike can be drawn as:
/\ _
\ /
\/\/

It’s clear that there is only one valley there, so we print on a new line.
Solution:

```import java.util.*;
class Main
{
public static int countingValley(int n, String path)
{
int level=0,valley=0;
for(int i=0;i<n;i++)
{
if(path.charAt(i)=='U')
level++;
else if(path.charAt(i)=='D')
{
if(level==1)
valley++;
level--;
}
}
return valley;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String str=sc.next();
int result=countingValley(n,str);
System.out.println(result);
}
}
```

To test your knowledge it is recommended to give Mock Tests by which you will know where you are lacking and will help you to crack your dream job.Go on, check it out and start giving the test!

5. Write a C Program to check if two given matrices are identical.

Solution:

```#include<bits/stdc++.h>
using namespace std;
#define N 4
// This function returns 1 if A[][] and B[][] are identical
// otherwise returns 0
int areSame (int A[][N], int B[][N])
{
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
if (A[i][j] != B[i][j])
return 0;
return 1;
}
int main ()
{
int A[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
int B[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
if (areSame (A, B))
cout<<"Matrices are identical";
else
cout<<"Matrices are not identical";
return 0;
}
```

6. A Pythagorean triplet is a set of three integers a, b and c such that a2 + b2 = c2. Given a limit, generate all Pythagorean Triples with values smaller than the given limit.

Input : limit = 20

Output : 3 4 5
8 6 10
5 12 13
15 8 17
12 16 20

A Simple Solution is to generate these triplets smaller than the given limit using three nested loops. For every triplet, check if the Pythagorean condition is true, if true, then print the triplet. Time complexity of this solution is O(limit3) where ‘limit’ is given limit.

An Efficient Solution can print all triplets in O(k) time where k is the number of triplets printed. The idea is to use square sum relation of Pythagorean triplet, i.e., addition of squares of a and b is equal to square of c, we can write these number in terms of m and n such that,
a = m2 – n2
b = 2 m n
c = m2 + n2
because,
a2 = m4 + n4 – 2 m2 n2
b2 = 4 m2 n2
c2 = m4 + n4 + 2 m2 n2

We can see that a2 + b2 = c2, so instead of iterating for a, b and c we can iterate for m and n and can generate these triplets

Solution:

```import java.util.*;
class Main
{
public static void pythagoreanTriplets(int limit)
{
int a,b,c=0;
int m=2;
while(c<limit)
{
for(int n=1;n<m;++n)
{
a=m*m-n*n;
b=2*m*n;
c=m*m+n*n;
if(c>limit)
break;
System.out.println(a+" "+b+" "+c);
}
m++;
}
}
public static void main(String[] args)
{
int limit=20;
pythagoreanTriplets(limit);
}
}
```

7. Problem Statement – Aashay loves to go to WONDERLA , an amusement park. They are offering students who can code well with some discount. Our task is to reduce the cost of the ticket as low as possible.
The cost of tickets can be removed by removing the digits from the price given. They will give some k turns to remove the digits from the price of the ticket. Your task is to help Aashay in coding a program that can help him to reduce the cost of a ticket by removing the digits from its price and getting the maximum possible discount.
Note – You cannot make the cost of a ticket zero. For eg -: If the cost of a ticket is 100, and you have 2 turns to reduce the price, the final price will be 1 and not zero.

Constraints:

• 1 <= number of tickets <= 105
• 1 <= K <= number of tickets

Input Format for Custom Testing:

• The first line contains a string,Tickets, denoting the given cost of each ticket.
• The next line contains an integer, K, denoting the number of tickets that is to be removed.

Sample Cases:

Sample Input 1
203
3

Sample Output 1
0

Solution:

```#include<bits/stdc++.h>
using namespace std;
int smallestNumber (string num, int k)
{
if(num.length()<=k)
return 0;

unordered_map<char,int> pos;
for(int i=0;i < num.length();i++)
{
pos[num[i]]=i;}

string temp=num;

sort(num.begin(),num.end());

string ans=num.substr(0,num.length()-k);
vector < int > v;

for(int i=0;i < ans.length();i++)
v.push_back(pos[ans[i]]);

sort(v.begin(),v.end());
string ret;
for(int i=0;i < v.size();i++)
{
ret+=temp[v[i]];
}
int final=stoi(ret);
return final;
}
int main()
{
string s; cin >> s;
int k;
cin >> k;
int ans;
cout << smallestNumber(s,k)%(int)(pow(10,9)+7);
return 0;
}
```

8. Problem Statement – In an airport , the Airport authority decides to charge some minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to the threshold then you have to pay \$1.
Returns: The function must return an INTEGER denoting the required amount to be paid.

Constraints:

• 1 <= N <= 105
• 1 <= weights[i] <= 105
• 1 <= T <= 105

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of luggages.
• Each line i of the N subsequent lines (where 0 <= i < n) contains an integer describing weight of ith luggage.
• The next line contains an integer, T, denoting the threshold weight of the boundary wall.

Sample Cases:

Sample Input 1
4
1
2
3
4
3

Sample Output 1
5

Explanation:
Here all weights are less than the threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.

Solution:

```#include <bits/stdc++.h>
using namespace std;

long int weightMachine(long int N,long int weights[],long int T)
{
long int amount=0,i;
for(i=0;i<N;i++) { amount++; if(weights[i]>T)
{
amount++;
}
}
return amount;
}
int main()
{
long int N,i,T;
cin>>N;

long int weights[N];
for(i=0;i<N;i++) { cin>>weights[i];
}
cin>>T;
cout<<weightMachine(N,weights,T);

return 0;
}
```

### Capgemini Exam Pattern FAQs

1. What is the average difficulty level for capgemini Papers?
These are hosted by Cocubes so instead of Capgemini Previous Papers, we analyze Cocubes, which generally is of moderate difficulty level thus Capgemini Previous Papers are also of the same difficulty but you must at least give 1 week for preparation.

2. From where should I prepare for Capgemini placement papers with answers?
For Capgemini Previous Placement Papers with Answers, PrepBytes is the best website you should be preparing from. We have all the previous year questions about the best material anywhere for Capgemini Test Papers with Solutions.

3. How many questions will be asked in the Capgemini Coding Test?
A total of 3 Questions will be asked in the Capgemini Test.

4. Does your study material consist of the entire syllabus for the capgemini exam?
Yes, our study material covers all the topics of all the sections of Capgemini. You can practice all types of questions 🙂