Other C++ Code Interview Questions 

Question 
Asked @ 
Answers 

how to find out the maximum number out of the three inputs. 
HP 
6 
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 
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 
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 
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 
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 
1. Write a program that performs the following. The user
inputs a number and then enters a series of numbers
from 1 to that number. Your program should determine
which number (or numbers) is missing or duplicated in
the series, if any. For example, if the user entered
5 as the initial number and then entered the
following sequences, the results should be as shown.
Input Sequence Output
 
1 2 3 4 5 Nothing bad
However, if 7 were the high number, the user
would see the results on the right for the following
number entries:
Input Sequence Output
 
1 3 2 4 5 Missing 6
Missing 7
And if 10 were the high number and the user
entered the numbers shown on the left, note the list
of missing and duplicate numbers:
Input Sequence Output
 
1 2 4 7 4 4 5 10 8 2 6 Duplicate 2 ( 2 times)
Missing 3
Duplicate 4 ( 3 times )
Missing 9


1 
a program using one dimensional array that searches a number
if it is found on the list of given input numbers given by
the user and locate its exact location in the list..
""EXAMPLE""
enter how many numbers to be inputted: 5
12 14 11 09 30
what number to search: 11
11 IS FOUND IN LOCATION 3
PLZZZ.. ELP ME...


3 
what is the best algorithm to sort out unique words from a
list of more than 10 million words(1 crore+)?
we need the best technique in the terms of execution time. 
TCS 
9 
Write an algorithm that receives a string and reverses it. 

2 
Find the maximum product of three numbers in an array?
Eg. 9,5,1,2,3
Max product= 9*5*3= 135
The array can hav negative numbers also.. 
CTS 
6 
What will be the output
for(i=1;i<=3;i++)
{
printf("%d",i);
continue;
i++;
} 
Impetus 
5 

For more C++ Code Interview Questions Click Here 