Other C++ Code Interview Questions 

Question 
Asked @ 
Answers 

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 c program, using for loop, that accepts and odds two
numbers. The output must be the sum and the addens. This
should be repeated 5 times while the first number is
decremented by one and the second number is incremented by 1.

IBM 
2 
write a program that calculate the volume of cylinder after
user enters radius and height and show the algorithm used 
JomoKenyattaUniversity 
1 
Faster Computers
Suppose you have a computer that requires 1 minute to solve
problem instances of size 1000. What instance sizes can be
run in 1 minute if you buy a new computer that runs 1000
times faster than the old one, assuming the following time
complexities T(n) for our algorithm?
(a) T(n) = O(n).
(b) T(n) = O(n3).
(c) T(n) = O(10n). 
QatarUniversity 
1 
Counting in Lojban, an artificial language developed over
the last fourty years, is easier than in most languages
The numbers from zero to nine are:
0 no
1 pa
2 re
3 ci
4 vo
5 mk
6 xa
7 ze
8 bi
9 so
Larger numbers are created by gluing the digit togather.
For Examle 123 is pareci
Write a program that reads in a lojban string(representing
a no less than or equal to 1,000,000) and output it in
numbers.


4 
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 
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 
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.

Amazon 
4 
can we declare an object of a class in another class?(assume
both class as public classes) 
Microsoft 
1 
Show by induction that 2n > n2, for all n > 4. 
QatarUniversity 
2 
What is the time complexity T(n) of the following program?
a)
int n, d, i, j;
cin >> n;
for (d=1; d<=n; d++)
for (i=1; i<=d; i++)
for (j=1; j<=n; j += n/10)
cout << d << " " << i << " " << j << endl;
b)
void main()
{ int n, s, t;
cin >> n;
for (s = 1; s <= n/4; s++)
{t = s;
while (t >= 1)
{ cout << s << " " << t << endl;
t;
}
}
}
c)
void main()
{ int n, r, s, t;
cin >> n;
for (r = 2; r <= n; r = r * 2)
for (s = 1; s <= n/4; s++)
{
t = s;
while (t >= 1)
{
cout << s << " " << t << endl;
t;
}
}
}

QatarUniversity 
3 
Write an algorithm that receives a string and reverses it. 

2 

For more C++ Code Interview Questions Click Here 