Categories of Questions

## Array Questions Capgemini

**Move all Negative Numbers to Beginning and Positive to End with Constant Extra Space** Suppose you have an array of integers. It consists of both negative and positive numbers and the problem statement asks to shift/move all the negative and positive elements to the left of the array and to the right of the array respectively without using extra space. Example Input: arr[]={2,4,-10,13,-7,-60,52,8,-19 } ...

**Sorting using trivial hash function** The problem “Sorting using trivial hash function” states that you are given an integer array. An array can be containing both negative and positive numbers. The problem statement asks to sort the array using Trivial Hash Function. Example arr[] = {5,2,1,3,6} {1, 2, 3, 5, 6} arr[] = {-3, -1, ...

**Given an Array of Pairs Find all Symmetric Pairs in it** Find all symmetric pairs – You are given some pairs of an array. You have to find out the symmetric pairs in it. The symmetric pair is said to be symmetric when in pairs say (a, b) and (c, d) in which ‘b’ is equal to ‘c’ and ‘a’ is ...

**Bubble sort using two Stacks** Problem Statement The problem “Bubble sort using two Stacks” states that you are given an array a[ ] of size n. Create a function to sort the given array a[ ] using a bubble sort paradigm with two stack data structures. Example a[ ] = {15, 12, 44, 2, 5, ...

**Next Greater Frequency Element** In the next greater frequency element problem, we have given an array a[ ] of size n containing numbers. For each number in the array print, the number to it’s right in an array with a frequency greater than that of the current number. Example Input a[] = {1, 1, ...

**Change the Array into Permutation of Numbers From 1 to N** In this problem, we have given an array A of n elements. We need to change the array into a permutation of numbers from 1 to n using minimum replacements in the array. Example Input: 2 2 3 3 Output: 2 1 3 4 Input : 3 2 1 7 ...

**Subtraction of Two Matrices** Problem Statement In the “Subtraction of Two Matrices” problem, we have given two matrices a and b. We have to find the final matrix after subtracting matrix b from matrix a. If the order is the same for both the matrices then only we can subtract them otherwise we can’t. ...

## String Questions Capgemini

**Reverse a String using Stack** We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input s = “TutorialCup” Output puClairotuT Input s = “Stack” Output kcatS Using Stack ...

**Program to Toggle all Characters in a String** Problem Statement In the “Program to Toggle all Characters in a String” problem we have given a string, write a program to toggle all characters of the given string. Here toggle means converting all the uppercase characters to lowercase and all lowercase characters to uppercase characters. Input Format The first ...

**Recursive Palindrome Check** Problem Statement In the “Recursive Palindrome Check” problem we have given a string “s”. We have to write a program to check if the given string is palindrome or not using recursion. A palindrome is a word, number, phrase, or other sequences of characters that reads the same backward as ...

**Remove Extra Spaces from a String** Problem Statement In the “Remove Extra Spaces from a String” problem we have given a string “s”. Write a program to remove all extra_spaces from the given string. Input Format The first and only one line containing a string s with some spaces. Output Format Print a string after removing ...

**Removing Spaces from a String using stringstream** Problem Statement In the “Removing Spaces from a String using stringstream” problem we have given a string “s”. Write a program that uses a string stream to remove spaces from the given string. Input Format The first and only one line containing a sentence/string “s”. Output Format The first line ...

## Stack Questions Capgemini

**Reverse a String using Stack** We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input s = “TutorialCup” Output puClairotuT Input s = “Stack” Output kcatS Using Stack ...

**Next Greater Frequency Element** In the next greater frequency element problem, we have given an array a[ ] of size n containing numbers. For each number in the array print, the number to it’s right in an array with a frequency greater than that of the current number. Example Input a[] = {1, 1, ...

## Matrix Questions Capgemini

**Subtraction of Two Matrices** Problem Statement In the “Subtraction of Two Matrices” problem, we have given two matrices a and b. We have to find the final matrix after subtracting matrix b from matrix a. If the order is the same for both the matrices then only we can subtract them otherwise we can’t. ...