C++ Interview Questions
- 0of 0 votes
AnswerWhat are the various ways of doing IPC in Unix/Linux? How do you implement it?
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Operating System unix system programmin - 0of 2 votes
AnswersDesign a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .
- gopi.komanduri August 02, 2014 in United States| Report Duplicate | Flag | PURGE
Computer Scientist Algorithm Android Application / UI Design Arrays Bit Manipulation C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Database Distributed Computing Dynamic Programming Hash Table Java Large Scale Computing Linked Lists Math & Computation Object Oriented Design Problem Solving Sorting SQL Stacks System Design Trees and Graphs XML - 0of 0 votes
AnswersDesign a phone book such that fields are searchable with name , with number. Later enhanced teh question asking searchable with address as well.
- gopi.komanduri July 22, 2014 in India| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays Bit Manipulation Brain Teasers C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures - 0of 0 votes
AnswersWhat happens when we pass negative indices to an array? Would the compiler allow it?
- learner123 July 17, 2014 in United States| Report Duplicate | Flag | PURGE
C++ - 0of 2 votes
AnswersHow to design a multi key hash map ( key count can be dynamic. if there are two keys , initiallly which can be used to find the value , keys can be increased to three as well ex: consider school structure. Intially , consider , student id is key , later , should be searchable even with key name , later with grade.
- gopi.komanduri July 05, 2014 in India| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays C# C++ Coding Data Structures Dynamic Programming Experience Hash Table Large Scale Computing Linked Lists Problem Solving Sorting Trees and Graphs - 1of 3 votes
AnswersDesign a telephone directory for large ppl (he gave example like design for India). fields will be , first name , last name , number . this should be searchable with first name , last name , number as welll.
- gopi.komanduri July 04, 2014 in India
later added more complexity like do the same for organisation where even it contains designations. so this should be searchable with designations.| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays C C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming Hash Table Ideas Large Scale Computing Linked Lists Object Oriented Design Problem Solving Trees and Graphs - 0of 0 votes
Answerswhat container will you choose if you should store numbers and check whether certain number is already stored?
- learner123 June 27, 2014 in United States| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersHow and where to initialize const data member in C++, if you did not initialize it in member initializes list?
- aap.shweta June 11, 2014 in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer C++ - 7of 7 votes
AnswersGiven a string (for example: "a?bc?def?g"), write a program to generate all the possible strings by replacing ? with 0 and 1.
- pennepalli May 30, 2014 in United States
Example:
Input : a?b?c?
Output: a0b0c0, a0b0c1, a0b1c0, a0b1c1, a1b0c0, a1b0c1, a1b1c0, a1b1c1.| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Algorithm C# C++ Java - 0of 0 votes
AnswersGiven a set of 21 tasks = {A, B,....Z} except I, O, U, X and Q. Each task requires 4 hours of processing. Except for tasks E, Y, P, R, W that require 8 hours of processing.
- foobar May 14, 2014 in United States
You have 3 machines to process these tasks = T1, T2, T3. T1 and T2 are available everyday for 8 hours. T3 is available only on Mon, Wed and Fri for 8 hours.
You are given 3 lists that indicate the dependency list among the tasks.
L1 = A->R->K->M (eg A can be completed if R is completed, R can be completed only if K is completed etc.)
L2 = N->G->V->E->Z->H
L3 = C->F->Y->D->J->P->T->S->W->B->C (cycle)
Each task needs one machine for its duration to complete.
Tasks cannot be resumed. Which means the 8 hour tasks cannot be executed over 2 days.
Each machine can process only one task at any time.
T1, T2 and T3 can process different tasks in parallel.
You are starting your schedule on a Wednesday.
Machines can be scheduled only during weekdays.
The first Monday in your schedule is a downtime for all the machines.
Given these constraints, write a program that generates a schedule between the tasks and machines such that all the tasks are completed at the
earliest.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm C++ Coding - 0of 0 votes
AnswersYou are given an array of N elements. Each element in the range Min of int to Max of Int. You need to find the length of longest sequence in this array such that difference of largest and smallest element of that sequence is 1. The sequence need not be sequential.
- northernlight May 06, 2014 in United Kingdom
For e.g. array[]={6,10,6,7,8,9,0}
seq {6,10} = diff is 4 len 2
seq { 10,7,8} diff is 3 len 3
seq { 7,8,9} diff 2 len 3
seq {6,6,7} diff is 1 len 3
In this example the program should return 3 .
Complexity N*longN| Report Duplicate | Flag | PURGE
Amazon Algorithm Arrays C C++ - 0of 0 votes
AnswersDo STL containers always create copy of objects when containers are populated (e.g. if you have a vector<A> or a map<int, A>, when we insert elements into vector/map, whether copies of object of class A would be stored inside the vector/map?
- learner123 April 24, 2014 in United States| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersHow can we achieve something similar to polymorphism in C language? Polymorphism is an OOPs feature.
- learner123 April 22, 2014 in United States| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersCan we write a collection class in C++ that can store elements of different data types?
- learner123 April 22, 2014 in United States| Report Duplicate | Flag | PURGE
C++ - 1of 1 vote
AnswersGiven a number in an array form, Come up with an algorithm to push all the zeros to the end.
- kiranpm86 February 24, 2014 in India
Expectation : O(n) solution| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - -1of 1 vote
AnswersGive 2 arrays of size 7 and 3 which are sorted such that the last 3 blocks in first array are empty, merge the arrays in a sorted manner in the most efficient way.
- kiranpm86 February 24, 2014 in India
E.g:-
a[7] = [4, 10, 11, 20__, __, __]
b[3] = [1,3,7]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - 0of 0 votes
AnswersHow do you implement stack in stl? What is the complexity?
- sasivara January 30, 2014 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is smart pointer? How do you implement? What happens with the following: p2 = p1;
- sasivara January 30, 2014 in United States
What happens P3(p1) (copy const)?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 0of 0 votes
AnswersI have declared one double pointer character array as given below:
- ermksharma2009 January 28, 2014 in India
char **errorcode;
so how to initialize this array with NULL.
and pass to other function?????| Report Duplicate | Flag | PURGE
Siemens Software Engineer / Developer C++ - 0of 0 votes
AnswersStruct node{
- renjumc January 28, 2014 in India
node *pNext;
node *pRandom;
};
You have a link list of the above node structure. pRandom has connection to any random nodes.
Write a program to clone this list.
note:You should not add any new items to node| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C C# C++ - -2of 2 votes
AnswersWrite a program to find the GCD of two numbers
- renjumc January 28, 2014 in India| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C C# C++ - 0of 0 votes
Answers
- aryan January 17, 2014 in IndiaA chessboard was given to us. Where in there was a Knight and King was placed oncertain positions. Our aim is to reach the king from the knight in minimum no of counts.As we know, knight can either move 2 steps vertical/horizontal and 1 stephorizontal/vertical. same goes here as well. Proper image of the chess board was given inthe question paper, and all the positions(max 8) were given that knight can take in thefirst step. Sol : Most of us implemented using recursive func
| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answers
- aryan January 17, 2014 in United StatesSeat Reservation prog for the theatre. Write a function for seat allocation for the movietickets. Total no of seats available are 200. 20 in each row. Each row is referred by theCharacter, "A" for the first row and ,J, for the last. And each seat in a row is represented by the no. 1-20. So seat in diffrent rows would be represented asA1,A2....;B1,B2.....;........J1,J2... Each cell in the table represent either 0 or 1. 0 rep wouldseat is available , 1 would represent seat is reserved.Booking should start from the last row (J) to the first row(A). At the max 20 seats can be booked at a time. if seats are available, then print all the seat nos like "B2" i.e (2 row, 3col) otherwise Print "Seats are not available." and we must book consecutive seats only
| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWhat is generics? How do you call a generic method in C++/C#? What are the disadvantages of generics?
- A.K. January 15, 2014 in United States for Shared file| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer C++ - 2of 2 votes
AnswersHow will you implement run-time polymorphism in C? There are two structs. There is a common function receiving only one argument(only one). The function should accept both base struct and derived struct objects and do corresponding actions. i.e if base struct object is passed, do base struct's task and vice versa
- chid1989 January 07, 2014 in United States| Report Duplicate | Flag | PURGE
NVIDIA Intern C++ - 0of 0 votes
AnswersThe way a Knight Given a chessboard, consisting of n×n cells, several of them are cut. Find the path of minimum length for a Knight from one cell to another. The Knight can’t go through cut cells.
- anas.love19 December 27, 2013 in United States
Specifications
Input
The first row is set to the number n (2 ≤ n ≤ 50). Each of the next n lines contains n symbols. The symbol # denotes the cut cell, the point - not cut cell, the symbol @ denotes the initial and final cell of the Knight's path (the chessboard contains two such characters).
Output If the path can not be constructed, print "Impossible". Otherwise display the same map as the input, but check all Knight intermediate positions with symbol @. Example
Example input
5
.....
.@@..
.....
.....
.....
5
@..@.
..##.
.....
.....
.....
5
@....
..#..
.#...
.....
....@
Example output
Sample 1
...@.
.@@..
....@
.....
.....
Sample 2
@..@.
..##.
.@..@
..@..
@....
Sample 3| Report Duplicate | Flag | PURGE
Student student C++ - -2of 4 votes
AnswersLook at the following pseudo-code, which computes the n-th Fibonacci number:
- Eliana December 24, 2013 in United States for interviews
int fibonacci(int n)
{
if (n == 0)
{
print(0)
return 0
}
if (n == 1)
{
print(1)
return 1
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
If one calls fibonacci(3), then the following will happen:
* fibonacci(3) calls fibonacci(2) and fibonacci(1) (the first call).
* fibonacci(2) calls fibonacci(1) (the second call) and fibonacci(0).
* The second call of fibonacci(1) prints 1 and returns 1.
* fibonacci(0) prints 0 and returns 0.
* fibonacci(2) gets the results of fibonacci(1) and fibonacci(0) and returns 1.
* The first call of fibonacci(1) prints 1 and returns 1.
* fibonacci(3) gets the results of fibonacci(2) and fibonacci(1) and returns 2.
In total, 1 will be printed twice and 0 will be printed once.
We want to know how many times 0 and 1 will be printed for a given integer N.
INPUT
The first line contains an integer T, denoting the number of test cases.
The next T lines contain an integer N.
OUTPUT
For each test case, print one line of output which contains 2 integers separated by a space. The first integer is the number of times 0 is printed. The second integer is the number of times 1 is printed.
CONSTRAINTS
1 <= T <= 50
0 <= N <= 40
SAMPLE INPUT
2
0
3
SMAPLEOUTPUT
1 0
1 2| Report Duplicate | Flag | PURGE
Informatica iOS Developer C++ - 0of 0 votes
AnswersLook at the following pseudo-code, which computes the n-th Fibonacci number:
- Eliana December 12, 2013 in United States for games developing
int fibonacci(int n)
{
if (n == 0)
{
print(0)
return 0
}
if (n == 1)
{
print(1)
return 1
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
If one calls fibonacci(3), then the following will happen:
* fibonacci(3) calls fibonacci(2) and fibonacci(1) (the first call).
* fibonacci(2) calls fibonacci(1) (the second call) and fibonacci(0).
* The second call of fibonacci(1) prints 1 and returns 1.
* fibonacci(0) prints 0 and returns 0.
* fibonacci(2) gets the results of fibonacci(1) and fibonacci(0) and returns 1.
* The first call of fibonacci(1) prints 1 and returns 1.
* fibonacci(3) gets the results of fibonacci(2) and fibonacci(1) and returns 2.
In total, 1 will be printed twice and 0 will be printed once.
We want to know how many times 0 and 1 will be printed for a given integer N.
INPUT
The first line contains an integer T, denoting the number of test cases.
The next T lines contain an integer N.
OUTPUT
For each test case, print one line of output which contains 2 integers separated by a space. The first integer is the number of times 0 is printed. The second integer is the number of times 1 is printed.
CONSTRAINTS
1 <= T <= 50
0 <= N <= 40
SAMPLE INPUT
2
0
3
SMAPLEOUTPUT
1 0
1 2| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C++ - 0of 0 votes
AnswersIf you look at the following pseudo-code, which computes the n-th Fibonacci number:
- Eliana December 12, 2013 in United States for games developing
int fibonacci(int n)
{
if (n == 0)
{
print(0)
return 0
}
if (n == 1)
{
print(1)
return 1
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
If one calls fibonacci(3), then the following will happen:
* fibonacci(3) calls fibonacci(2) and fibonacci(1) (the first call).
* fibonacci(2) calls fibonacci(1) (the second call) and fibonacci(0).
* The second call of fibonacci(1) prints 1 and returns 1.
* fibonacci(0) prints 0 and returns 0.
* fibonacci(2) gets the results of fibonacci(1) and fibonacci(0) and returns 1.
* The first call of fibonacci(1) prints 1 and returns 1.
* fibonacci(3) gets the results of fibonacci(2) and fibonacci(1) and returns 2.
In total, 1 will be printed twice and 0 will be printed once.
We want to know how many times 0 and 1 will be printed for a given integer N.
INPUT
The first line contains an integer T, denoting the number of test cases.
The next T lines contain an integer N.
OUTPUT
For each test case, print one line of output which contains 2 integers separated by a space. The first integer is the number of times 0 is printed. The second integer is the number of times 1 is printed.
CONSTRAINTS
1 <= T <= 50
0 <= N <= 40
SAMPLE INPUT
2
0
3
SMAPLEOUTPUT
1 0
1 2| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C++