CAPGEMINI CODING QUESTIONS
Question 1: Ball Distribution
Alice has N balls. She wants to distribute these balls among people in such a way that:
● The 1st person gets 1 ball,
● The 2nd person gets 2 balls,
● The 3rd person gets 3 balls, and so on.
Determine the maximum number of people Alice can distribute the balls to, following this
pattern.
Input:
● A single integer, N (the total number of balls Alice has).
Output:
● An integer representing the maximum number of people who can receive the balls.
Question 2: Nearest Digits and Fibonacci Sum
You are given an integer N. Perform the following steps:
1. Find the two nearest digits to N.
2. Calculate the product of these two digits.
3. Generate the Fibonacci sequence up to the number of terms equal to the product
obtained in step 2.
4. Find the sum of the Fibonacci sequence generated.
Input:
● A single integer N.
Output:
● A single integer representing the sum of the Fibonacci sequence.
Question 3: Minimum Difference and Fibonacci Sum
You are given:
● An array of integers arr,
● A target integer t, and
● An integer k.
Perform the following steps:
1. Find the k elements in the array that have the smallest absolute difference from the
target t.
2. Calculate the product of these k elements.
3. Generate the Fibonacci sequence up to the value of the product obtained in step 2.
4. Calculate the sum of the Fibonacci sequence.
Input:
● arr: List of integers representing the array.
● t: An integer representing the target.
● k: An integer representing how many elements to consider.
Output:
● A single integer representing the sum of the Fibonacci sequence.
Question 4: Points and Sections Scoring
You are given:
● A range of numbers [l, r], and
● A list of sections, where each section is defined as [start, end].
For each point in the range [l, r], calculate its score, where the score of a point is the number of
sections it falls within.
Input:
● l: The starting number of the range (integer).
● r: The ending number of the range (integer).
● sections: A list of pairs, where each pair represents the start and end of a section.
Output:
● A list of scores for all points in the range [l, r].
Question 5: Nearest Number and Fibonacci Sum
You are given:
● An array of integers arr,
● A target integer target, and
● A key integer key.
Perform the following steps:
1. Find the number in the array nearest to the target.
2. Generate the Fibonacci sequence up to the value of the key.
3. Calculate the sum of the Fibonacci sequence.
Input:
● arr: A list of integers.
● target: An integer representing the target value.
● key: An integer representing the range of Fibonacci numbers to generate.
Output:
● A single integer representing the sum of the Fibonacci sequence.
Question 6: Buildings and Sunset View
You are given n buildings, each with a specific height. The buildings are arranged in a straight
line from left to right. A building can "watch the sunset" if it is taller than all the buildings to its
left.
Write a program to calculate how many buildings can watch the sunset.
Input:
● n: An integer representing the number of buildings.
● heights: A list of integers of size n, where each integer represents the height of a
building.
Output:
● An integer representing the number of buildings that can watch the sunset.
Question 7: Range and Point Scoring
You are given:
● A range of numbers [l, r].
● A list of points.
For each point, calculate its score, where the score of a point is the total number of numbers
from the range [l, r] it lies within.
Input:
● l: Start of the range (integer).
● r: End of the range (integer).
● points: A list of integers representing the points.
Output:
● A list of integers representing the scores of each point.
Question 8: Maximum Number of Overlapping Ranges
You are given:
1. An integer n representing the number of ranges.
2. Two integers x and y, representing a start and end point.
3. n ranges, where each range is represented as [a, b].
Your task is to find the maximum number of overlapping ranges for every integer in the interval
[x, y]. Additionally, calculate the sum of the maximum overlap counts for all integers in [x, y].
Input:
● First line: An integer n, the number of ranges.
● Second line: Two integers x and y, the start and end of the interval to evaluate.
● Next n lines: Two integers a and b for each range, representing the start and end points
of the ranges.
Output:
● An integer representing the sum of maximum overlaps for all integers in [x, y].