Other C++ Code Interview Questions 

Question 
Asked @ 
Answers 

Write a program that takes a 3 digit number n and finds out
whether the number 2^n + 1 is prime, or if it is not prime
find out its factors. 
TCS 
2 
A research student is given a singlylinked list. Each node
of the list has a color, which is either “Black”
or “White”. He must find if there are more black nodes than
white nodes, or vice versa. His advisor
gives him 5,000Rs to buy a computer to do the work. He goes
to the computer store and finds a
slightly defective computer which costs a mere 3,000Rs. This
computer has the small problem of not
being able to do arithmetic. This means that he cannot use a
counter to count the nodes in the list to
determine the majority color. The computer is otherwise
fully functional. He has the evil idea that he
could buy the defective computer and somehow use it to do
his work, so that he can use the rest of
the money on enjoyment. Show how he can accomplish this
amazing task. Write code for an algorithm
called ‘findMajorityColor’ which takes a singlylinked list,
L, with n nodes and returns the majority color
among nodes of L. This algorithm should have the same
asymptotic running time as counting the
nodes (O(n)). Note: No arithmetic is allowed. 

1 
write a function – oriented program that calculates the sum
of the squares from 1 to n. thus, if the input is 3, the
output is 14 

3 
Deriving time complexity of Binary tree and AVL tree, step
by step. 
NetApp 
4 
Write a program using one dimensional array that searches a
number and display the number of times it occurs on the list
of 12 input values.
Sample input/output dialogue:
Enter 12 values:
13 15 20 13 30 35 40 16 18 20 18 20
Enter number to search: 20
Occurences: 3


2 
. Remove all the blank spaces between
character.Matrix is of 10* 10.
eg: INPUT

 N  A   V  T

 G  U  P 

T    A  

OUTPUT:

 N  A  V  T  

G U  P   

T  A    


Nagarro 
2 
1. Write a program using one dimensional array that
calculates the sum and average of the five input values from
the keyboard and prints the calculated sum and average. 

2 
main(){int a=5,b 10,c=2, d;a=b c;d=++a=(c)*2;
printf("%d%d%d%d,a,b,c,d; return o;} 

1 
Algorithm in O(2n)
Presently we can solve in our hypothetical machine problem
instances of size 100 in 1 minute using algorithm A, which
is a O(2n). We would like to solve instances of size 200 in
1 minute using algorithm A on a new machine.
What is the speed of the new machine should be? 
QatarUniversity 
2 
Here's the programm code:
int magic(int a, int b) {
return b == 0 ? a : magic(b, a % b);
}
int main() {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", magic(a, b));
return 0;
}
on input stream we have integers 4, 45
What's the output integer?
How many times will be initiated "magic" function? 

1 
Perform the functionality of 2D array through 1D array
and in it the functions to be performed were:
(1) Display the array in 2D format
(2) Display a particular element
(3) Display a particular row
(4) Display a particular column

Nagarro 
1 
How do I store linked list datas into an array?


1 

For more C++ Code Interview Questions Click Here 