Capgemini Interview Questions
Showing 24 questions
Find two numbers in a given array that add up to a specific target value, and return their indices. Essentially, you need to efficiently locate the pair that satisfies the sum requirement.
#1. Two Sum
Given a string, find the most frequent character that appears earliest in the string. Return the length of the shortest substring that contains all occurrences of this character.
#2. Reverse Degree of a String
Given a sorted array, remove the duplicate elements in-place such that each unique element appears only once. Return the new length of the array.
#3. Remove Duplicates from Sorted Array
Find the number of elements in an array that appear with the highest frequency. Essentially, count how many times the most frequent number occurs.
#4. Count Elements With Maximum Frequency
You're given daily stock prices. Find the maximum profit you can make by buying and selling the stock once. You must buy before you sell.
#5. Best Time to Buy and Sell Stock
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#6. Move Zeroes
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#7. Palindrome Number
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#8. Longest Substring Without Repeating Characters
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#9. Longest Common Prefix
You're given two sorted lists. Combine them into a single sorted list containing all elements from both original lists.
#10. Merge Two Sorted Lists
Given an array, rotate the elements to the right by a specified number of steps. The goal is to modify the original array in-place with the rotated elements.
#11. Rotate Array
Given a sorted array, find the first and last position of a given target value. If the target is not found, return [-1, -1].
#12. Find First and Last Position of Element in Sorted Array
Construct the longest possible string using limited quantities of 'a', 'b', and 'c', ensuring that no three consecutive characters are the same. Return the longest string satisfying this constraint.
#13. Longest Happy String
You are given two linked lists, each representing a non-negative integer. Add the two numbers and return the sum as a linked list.
#14. Add Two Numbers
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#15. Valid Parentheses
Given a set of coin denominations and a target amount, find the minimum number of coins needed to reach that amount. You can assume you have an unlimited supply of each coin type.
#16. Coin Change
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. These consecutive numbers do not need to be adjacent in the original array.
#17. Longest Consecutive Sequence
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#18. Median of Two Sorted Arrays
Given an array representing the height of bars, calculate how much water can be trapped between them after rain. Think about finding the maximum height to the left and right of each bar.
#19. Trapping Rain Water
You're given an array containing only 0s, 1s, and 2s. Sort the array in place so that elements of the same value are grouped together.
#20. Sort Colors