100% found this document useful (1 vote)
1K views

Capgemini Coding CheatSheet

Practice Coding Questions For Capgemini

Uploaded by

prathambankar16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Capgemini Coding CheatSheet

Practice Coding Questions For Capgemini

Uploaded by

prathambankar16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1:1 MOCK SESSION WWW.PRIMCECODING.

IN 1:1 MOCK SESSION

Capgemini Coding CheatSheet

1. Problem Statement –

Capgemini in its online written test have a coding question, wherein the
students are given a string with multiple characters that are repeated
consecutively. You’re supposed to reduce the size of this string using
mathematical logic given as in the example below :

G
Input :
aabbbbeeeeffggg

IN
Output:

a2b4e4f2g3

D
O
2. Problem Statement –

Write the code to traverse a matrix in a spiral format.


C
Sample Input

Input
E

5 4
IM

1 2 3 4

5 6 7 8

9 10 11 12
PR

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

3. Problem Statement –

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
1
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

You’re given an array of integers, print the number of times each integer has
occurred in the array.
Example

Input :

10

1233414512

Output :

1 occurs 3 times

G
2 occurs 2 times

3 occurs 2 times

IN
4 occurs 2 times

5 occurs 1 times

D
O
4. Problem Statement –
C
Write a function to solve the following equation a3 + a2b + 2a2b + 2ab2 +
ab2 + b3.
E

Write a program to accept three values in order of a, b and c and get the result
of the above equation.
IM
PR

5. 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

42
40

12

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
2
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Output

20

16

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

G
Total number of tyres in dealerships1 is (4 x 4) + (2 x 2) = 20

IN
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

D
O
6. Problem Statement

Bela teaches her daughter to find the factors of a given number. When she
C
provides a number to her daughter, she should tell the factors of that number.
Help her to do this, by writing a program. Write a class FindFactor.java and
write the main method in it.
E

Note :
IM

If the input provided is negative, ignore the sign and provide the output. If
the input is zero
PR

If the input is zero the output should be “No Factors”.

Sample Input 1:

54

Sample Output 1:

1, 2, 3, 6, 9, 18, 27, 54

7. Problem Statement

Raj wants to know the maximum marks scored by him in each semester. The
mark should be between 0 to 100 ,if it goes beyond the range display “You

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
3
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

have entered invalid mark.”

Sample Input 1:

Enter no of semester:3

Enter no of subjects in 1 semester:3

Enter no of subjects in 2 semester:4

Enter no of subjects in 3 semester:2

Marks obtained in semester 1:506070

G
Marks obtained in semester 2:90987667

Marks obtained in semester 3:8976

IN
Sample Output 1:

Maximum mark in 1 semester:70

Maximum mark in 2 semester:98

Maximum mark in 3 semester:89


D
O
C
8. Problem Statement

Mayuri buys “N” no of products from a shop. The shop offers a different
E

percentage of discount on each item. She wants to know the item that has
the minimum discount offer, so that she can avoid buying that and save
IM

money.[Input Format: The first input refers to the no of items; the second
input is the item name, price and discount percentage separated by
comma(,)]Assume the minimum discount offer is in the form of Integer.Note:
PR

There can be more than one product with a minimum discount.

Sample Input 1:

4
mobile,10000,20

shoe,5000,10
watch,6000,15

laptop,35000,5

Sample Output 1:

shoe

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
4
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Explanation: The discount on the mobile is 2000, the discount on the shoe is
500, the discount on the watch is 900 and the discount on the laptop is 1750.
So the discount on the shoe is the minimum.

9. Problem Statement

You have write a function that accepts, a string which length is “len”, the
string has some “#”, in it you have to move all the hashes to the front of the
string and return the whole string back and print it.

G
char* moveHash(char str[],int n);

IN
example :-

Sample Test Case


Input:

Move#Hash#to#Front D
O
Output:

MoveHashtoFront
C
E

10. Shraddha Kapoor’s professor suggested that she study hard and prepare
IM

well for the lesson on seasons. If her professor says month then, she has
to tell the name of the season corresponding to that month. So write the
program to get the solution to the above task?
PR

March to May – Spring Season

June to August – Summer Season

September to November – Autumn Season

December to February – Winter Season

Note: The entered month should be in the range of 1 to 12. If the user enters a
month less than 1 or greater than 12 then the message “Invalid Month Entered”
should get displayed.

Sample Input 1:

Enter month: 6

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
5
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Sample Output 1:

Season: Summer

11. Counting Valleys:

Problem: Given a sequence of up and down steps during a hike, determine


the number of valleys traversed.

Input:

G
8

IN
UDDDUDUU

Output: 1

D
Explanation: A valley is a sequence of consecutive steps below sea level.
The example describes a single valley.
O
C
12. Matrix Identity Check:

Problem: Write a program to check if two given matrices are identical.


E

Input:
IM

Matrix A: [[1,1,1,1], [2,2,2,2], [3,3,3,3], [4,4,4,4]]

Matrix B: [[1,1,1,1], [2,2,2,2], [3,3,3,3], [4,4,4,4]]


PR

Output: Matrices are identical

Explanation: The program checks each corresponding element in both


matrices for equality.

13. Pythagorean Triplets:

Problem: Generate all Pythagorean triplets with values smaller than a given
limit.

Input: limit = 20

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
6
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Output:

3 4 5

8 6 10

5 12 13

15 8 17

12 16 20

Explanation: The triplets satisfy the condition a² + b² = c² , where a , b ,


and c are integers.

G
IN
14. Binary Search:

Problem: Implement a binary search algorithm to find a target value in a


sorted array.

Input: D
O
Array: [1, 2, 3, 4, 5, 6, 7, 8, 9]
C
Target: 4

Output: 3

Explanation: The function returns the index of the target value in the
E

array.
IM

15. String Rotation:


PR

Problem: Determine if one string is a rotation of another.

Input:

String A: "ABCD"

String B: "CDAB"

Output: True

Explanation: B is a rotation of A .

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
7
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

16. Find the Missing Number in an Array:

Problem: Given an array containing n-1 integers in the range from 1 to

n , find the missing number.

Input:

Array: [1, 2, 4, 5, 6]

Output: 3

Explanation: The missing number is 3 .

G
17. Reverse a Linked List:

IN
Problem: Write a function to reverse a singly linked list.

Input:

Output:
1 -> 2 -> 3 -> 4 -> 5

D
O
5 -> 4 -> 3 -> 2 -> 1
C
Explanation: The list is reversed.

18. Longest Substring Without Repeating Characters:


E

Problem: Given a string, find the length of the longest substring without
repeating characters.
IM

Input:

String: "abcabcbb"
PR

Output: 3

Explanation: The longest substring is "abc" , which has a length of 3.

19. Find the Duplicates in an Array:

Problem: Find duplicates in a given array of integers.

Input:

Array: [4, 3, 2, 7, 8, 2, 3, 1]

Output:

Duplicates: 2, 3

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
8
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Explanation: Numbers 2 and 3 are repeated.

20. Check if a Number is Prime:

Problem: Write a function to check if a given number is prime.

Input:

Number: 29

Output: True

Explanation: 29 is a prime number.

G
21. Merge Two Sorted Arrays:

Problem: Merge two sorted arrays into a single sorted array.

IN
Input:

Array 1: [1, 3, 5]

Output:
Array 2: [2, 4, 6]
D
O
[1, 2, 3, 4, 5, 6]
C
22. Rotate an Array:

Problem: Rotate an array by k steps to the right.


E

Input:
IM

Array: [1, 2, 3, 4, 5]

k = 2

Output:
PR

[4, 5, 1, 2, 3]

Explanation: The array is rotated by 2 positions.

23. Check for Balanced Parentheses:

Problem: Given a string containing just the characters ( , ) , { , } , [

and ] , determine if the input string is valid.

Input:

String: "{[()]}"

Output:

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
9
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

True

Explanation: The string has balanced parentheses.

24. Largest Sum Contiguous Subarray (Kadane’s Algorithm):

Problem: Find the maximum sum of a contiguous subarray.

Input:

Array: [-2, 1, -3, 4, -1, 2, 1, -5, 4]

Output:

G
6

Explanation: The subarray [4, -1, 2, 1] has the largest sum = 6.

IN
25. Find the Intersection of Two Arrays:

Problem: Find the intersection of two unsorted arrays.

Input:
D
O
Array 1: [1, 2, 2, 1]

Array 2: [2, 2]
C
Output:

[2]
E

Explanation: The common element between the arrays is 2 .


IM

26. Check for Palindrome:

Problem: Given a string, check if it is a palindrome.


PR

Input:

String: "racecar"

Output: True

Explanation: The string reads the same backward as forward.

27. Matrix Rotation by 90 Degrees:

Problem: Rotate a 2D matrix by 90 degrees clockwise.


Input:

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
10
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Output:

[[7, 4, 1], [8, 5, 2], [9, 6, 3]]

Explanation: The matrix is rotated 90 degrees clockwise.

28. Find the Majority Element:

Problem: Given an array of size n , find the majority element (appears more
than n/2 times).

G
Input:

IN
Array: [2, 2, 1, 1, 1, 2, 2]

Output:

Explanation: The number 2 D


appears more than n/2 times.
O
29. Find the First Non-Repeated Character in a String:
C

Problem: Given a string, find the first character that does not repeat.

Input:
E

String: "swiss"
IM

Output:

w
PR

Explanation: 'w' is the first character that does not repeat in the string.

30. Merge Intervals:

Problem: Given a collection of intervals, merge all overlapping intervals.

Input:

Intervals: [[1,3],[2,6],[8,10],[15,18]]

Output:

[[1,6],[8,10],[15,18]]

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
11
1:1 MOCK SESSION WWW.PRIMCECODING.IN 1:1 MOCK SESSION

Explanation: Intervals [1,3] and [2,6] overlap, so they are merged into
[1,6]. The others remain unchanged.

G
IN
D
O
C
E
IM
PR

Capgemini Coding CheatSheet


WWW.PRIMCECODING.IN 1:1 MOCK SESSION
12

You might also like