Other C++ Code Interview Questions 

Question 
Asked @ 
Answers 

void main()
{
int i,j=2;
for(i=0;i<3;i++)
if(j=i)
cout<<"Lotus ";
else
cout<<"Rose ";
}
Its result is Rose Lotus Lotus.. How? Explain it? 

2 
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 
Complexity T(n)
Write a lineartime algorithm that sorts n distinct
integers, each of which is between 1 and 500.
Hint: Use a 500element array. (Lineartime means your
algorithm runs in time c*n + b, where c and b are any
constants that do not depend on n.
For example, your algorithm can run in time n, or time 2n +
1, or time 5n + 10, or time 100n + 6, but not time c*n*n =
c*n?.) 
QatarUniversity 
1 
using repetition structure. Write a c program that will
accept five numbers. The program should count and output the
total count of even numbers and total count of add numbers.


2 
Deriving time complexity of Binary tree and AVL tree, step
by step. 
NetApp 
4 
PROBLEM #8 The cashier at the counter of a Super Store, Mr.
Khazaanchi has the following
bundles of rupee cash notes with him:
Rs. 1, 2, 5, 10, 50, 100, 500, 1000
A customer comes at his counter with various items that he
has shopped. Mr. Khazaanchi totals
the item prices and tells the customer his total amount
payable. The customer gives Mr. Khazanchi
some amount of cash. Find the total number of rupee notes of
each denomination (i.e. 1, 2, 5, 10,
50, 100, 500, 1000) Mr. Khazaanchi will have to give to the
withdrawer ensuring that the total
number of rupee notes are minimum. 

1 
MinMax
Write an algorithm that finds both the smallest and
largest numbers in a list of n numbers and with complexity
T(n) is at most about (1.5)n comparisons. 
QatarUniversity 
10 
write a program that can locate elements in array. 

1 
A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
OUTPUT: E


1 
Write a function oriented to convert the input dollar(s)
into its equivalent peso. Assume that one dollar is
equivalent to 51.60 

1 
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 
what is virtual constroctor ? give an exam for it?(parimal
dhimmar) 

2 

For more C++ Code Interview Questions Click Here 