0% found this document useful (0 votes)
27 views7 pages

CG - Coding

Uploaded by

Harsh Anmol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

CG - Coding

Uploaded by

Harsh Anmol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CG – Coding Questions

Question – 01.

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.

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

example :-

Sample Test Case

Input:

Move#Hash#to#Front

Output:

###MoveHashtoFront

In C:
In C++:

In Java:
Question – 02.

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 :

Input :

aabbbbeeeeffggg

Output:

a2b4e4f2g3

Input :

abbccccc

Output:

ab2c5

In C:
Question – 03.

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
Question – 04.

Problem Statement –

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

2 occurs 2 times

3 occurs 2 times

4 occurs 2 times

5 occurs 1 times
Question – 05.

Problem Statement –

Write a function to solve the following equation a3 + a2b + 2a2b + 2ab2 + ab2 + b3.

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

Question – 06.

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

42

40

12

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


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

You might also like