C++ Interview Questions
- 0of 0 votes
Answertower Of Hanoi using priority queue
- amit April 02, 2015 in India| Report Duplicate | Flag | PURGE
Motorola Android Engineer C++ - 2of 2 votes
AnswersPoint errors (if any) in the following pointer code and explain what it does...
- Jeanclaude March 17, 2015 in United States
char* cp(char *a)
{
char *f;
f=(char*)malloc(strlen(a)*sizeof(char));
while(*a != 0)
{
*f=*a;
f++;
a++;
}
cout<< f;
return f;
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test C++ - 0of 0 votes
AnswersPrint the following pattern using C/C++
- deepanshuchg March 14, 2015 in India
(For n=4)
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1
PS: Printing above triangle is easy and I easily did it, but couldn't print the lower triangle.| Report Duplicate | Flag | PURGE
Josh Software Developer C++ - 0of 0 votes
AnswersIn C++, what's the difference between public and private? what's the purpose of this and please illustrate a design example with this.
- ycw March 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer C++ - 0of 0 votes
AnswersThe SHIELD is a secretive organization entrusted with the task of guarding the world against any disaster. Their arch nemesis is the organization called HYDRA. Unfortunately some members from HYDRA had infiltrated into the SHIELD camp. SHIELD needed to find out all these infiltrators to ensure that it was not compromised.
- reddygokul.i7 February 26, 2015 in India
Nick Fury, the executive director and the prime SHIELD member figured out that every one in SHIELD could send a SOS signal to every other SHIELD member he knew well. The HYDRA members could send bogus SOS messages to others to confuse others, but they could never receive a SOS message from a SHIELD member. Every SHIELD member would receive a SOS message ateast one other SHIELD member, who in turn would have received from another SHIELD member and so on till NickFury. SHIELD had a sophisticated mechanism to capture who sent a SOS signal to whom. Given this information, Nick needed someone to write a program that could look into this data and figure out all HYDRA members.
Sample Input
Nick Fury : Tony Stark, Maria Hill, Norman Osborn
Hulk : Tony Stark, HawkEye, Rogers
Rogers : Thor,
Tony Stark: Pepper Potts, Nick Fury
Agent 13 : Agent-X, Nick Fury, Hitler
Thor: HawkEye, BlackWidow
BlackWidow:Hawkeye
Maria Hill : Hulk, Rogers, Nick Fury
Agent-X : Agent 13, Rogers
Norman Osborn: Tony Stark, Thor
Sample Output
Agent 13, Agent-X, Hitler
You can code in any language of your choice. Input and Output must be in the same format as above| Report Duplicate | Flag | PURGE
xyz Algorithm C++ Java Python - 0of 0 votes
AnswersReverse left node of BT.
- frustatedALGO February 12, 2015 in United States
1 (ROOT)
/ \
2 3
/ \
4 5
/ \
6 7
to
1
/
2 - 3
/
4 - 5
/
6 - 7
(6 is root)| Report Duplicate | Flag | PURGE
xyz Software Engineer / Developer C++ - 0of 0 votes
AnswersWrite a utility function that takes the starting position (P0) and length (L0) of one line segment plus the start position (P1) and length (L1) of a second line segment and returns the configurations where both segments end at the same point. Both starting points can be anywhere in three dimensional space.
- GameDev33 February 09, 2015 in United States| Report Duplicate | Flag | PURGE
Software Engineer Algorithm C++ Math & Computation Matrix - 0of 0 votes
AnswerThe problem is to write a set of functions to manage a variable number of byte queues, each with variable length, in a small, fixed amount of memory.
You should provide implementations of the following four functions:
// Creates a FIFO byte queue, returning a handle to it.
Q * create_queue();
// Destroy an earlier created byte queue.
void destroy_queue(Q * q);
// Adds a new byte to a queue.
void enqueue_byte(Q * q, unsigned char b);
// Pops the next byte off the FIFO queue
unsigned char dequeue_byte(Q * q);
So, the output from the following set of calls:Q * q0 = create_queue(); enqueue_byte(q0, 0); enqueue_byte(q0, 1); Q * q1 = create_queue(); enqueue_byte(q1, 3); enqueue_byte(q0, 2); enqueue_byte(q1, 4); printf("%d", dequeue_byte(q0)); printf("%d\n", dequeue_byte(q0)); enqueue_byte(q0, 5); enqueue_byte(q1, 6); printf("%d", dequeue_byte(q0)); printf("%d\n", dequeue_byte(q0)); destroy_queue(q0); printf("%d", dequeue_byte(q1)); printf("%d", dequeue_byte(q1)); printf("%d\n", dequeue_byte(q1)); destroy_queue(q1);
should be:
- GameDev33 February 09, 2015 in United States
0 1
2 5
3 4 6
You can define the type Q to be whatever you want.
Your code is not allowed to call malloc() or other heap management routines. Instead, all storage (other than local variables in your functions) must be within a provided array:
unsigned char data[2048];
Memory efficiency is important. On average while your system is running, there will be about 15 queues with an average of 80 or so bytes in each queue. Your functions may be asked to create a larger number of queues with less bytes in each. Your functions may be asked to create a smaller number of queues with more bytes in each.
Execution speed is important. Worst-case performance when adding and removing bytes is more important than average-case performance.
If you are unable to satisfy a request due to lack of memory, your code should call a provided failure function, which will not return:
void on_out_of_memory();
If the caller makes an illegal request, like attempting to dequeue a byte from an empty queue, your code should call a provided failure function, which will not return:
void on_illegal_operation();
There may be spikes in the number of queues allocated, or in the size of an individual queue. Your code should not assume a maximum number of bytes in a queue (other than that imposed by the total amount of memory available, of course!)
You can assume that no more than 64 queues will be created at once.| Report Duplicate | Flag | PURGE
Software Engineer C C++ - 1of 1 vote
AnswersWhat is Encapsulation? What is inheritance? When and Why should you use the inheritance?
- joeyk December 06, 2014 in United States for Supply Chain| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ - 1of 1 vote
AnswersGiven a number,print it in words.
- Pooja Karadgi November 26, 2014 in India
19621 -> One lakh ninety six thousand and twenty one.| Report Duplicate | Flag | PURGE
FactSet Research Systems, Inc Software Engineer / Developer C C++ - 0of 0 votes
Answersclass template vs template class?
- shailendra.rajput November 13, 2014 in India
c++ specific properties?
struct vs class?
encapsulation vs abstraction?
Design a holder - bulbs(LED,Normal,Tube light) - uml relation ship?
multiple inheritance, multiple level inheritance-CTOR and DTOR order for base classes ?
why use templates?
what is abstract class?
unit testing tools used?
smart poiner vs dangling pointer
why we take "Base& obj" as input in Base Copy CTOR function, in Base(Base& obj){}, why not "Base obj".
shallow copy vs Deep copy.| Report Duplicate | Flag | PURGE
Dover Organization Dev Lead Dev Lead C++ - 1of 1 vote
AnswersAbstract
- sai November 07, 2014 in United States for engineer
We are planning an orienteering game.
The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance.
However, the players have to pass all the checkpoints (@) on the map.
An orienteering map is to be given in the following format.
########
#@....G#
##.##@##
#..@..S#
#@.....#
########
In this problem, an orienteering map is to be given.
Calculate the minimum distance from the start to the goal with passing all the checkpoints.
Specification
* A map consists of 5 characters as following.
You can assume that the map does not contain any invalid characters and
the map has exactly one start symbol 'S' and exactly one goal symbol 'G'.
* 'S' means the orienteering start.
* 'G' means the orienteering goal.
* '@' means an orienteering checkpoint.
* '.' means an opened-block that players can pass.
* '#' means a closed-block that players cannot pass.
* It is allowed to move only by one step vertically or horizontally (up, down, left, or right) to the
next block.
Other types of movements, such as moving diagonally (left up, right up, left down and right down)
and skipping one or more blocks, are NOT permitted.
* You MUST NOT get out of the map.
* Distance is to be defined as the number of movements to the different blocks.
* You CAN pass opened-blocks, checkpoints, the start, and the goal more than once if necessary.
* You can assume that parameters satisfy following conditions.
* 1 <= width <= 100
* 1 <= height <= 100
* The maximum number of checkpoints is 18.
* Return -1 if given arguments do not satisfy specifications, or players cannot arrive at the goal
from the start by passing all the checkpoints.
1/6
Examination 1
*You can choose Java or C++| Report Duplicate | Flag | PURGE
job tessio job tessio job tessio job tessio C++ - 9of 9 votes
AnswersGiven a string (1-d array) , find if there is any sub-sequence that repeats itself.
- for.anonymous.usa October 22, 2014 in United States
Here, sub-sequence can be a non-contiguous pattern, with the same relative order.
Eg:
1. abab <------yes, ab is repeated
2. abba <---- No, a and b follow different order
3. acbdaghfb <-------- yes there is a followed by b at two places
4. abcdacb <----- yes a followed by b twice
The above should be applicable to ANY TWO (or every two) characters in the string and optimum over time.
In the sense, it should be checked for every pair of characters in the string.| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm Brain Teasers C C++ Coding Data Structures Dynamic Programming Problem Solving String Manipulation - 0of 0 votes
AnswersImplement bool isPalindrome(SingleLinkList *node) in constant Space.
- hprem991 October 11, 2014 in United States for Chennei
Sorry for incomplete post earlier..| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
AnswersImplement bool regex() Function.
- hprem991 October 11, 2014 in India for Chennei| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ Coding - 1of 1 vote
AnswersImplement bool isBST(Tree * root)
- hprem991 October 11, 2014 in India for Chennei| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ Coding - 1of 3 votes
AnswersA Multi-threaded server application stops working and the last log message from the application is:
"Some Server Related Message..."
Code looks like:
CalledFunc () { Code ... Acquiring Thread lock Line printing "Some Server Related Message..." Func(); Releasing Thread Lock }
1. What should the programmer in charge do to debug this?
- joe.wynton October 07, 2014 in United States for Trading System
2. What has happened wrong in the Func()?
3. If an exception is thrown in the Func() what should be done to fix problem ?| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer C# C C++ Threads - 0of 0 votes
AnswersA Multi-threaded server application stops working and the last log message from the application is:
"Some Server Related Message..."
Code looks like:
CalledFunc () { Code ... Acquiring Thread lock Line printing "Some Server Related Message..." Func(); Releasing Thread Lock }
1. What should the programmer in charge do to debug this?
- joe.wynton October 07, 2014 in United States
2. What has happened wrong in the Func() ?
3. If an exception is thrown in the Func() what should be done to fix problem ?| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer C# C C++ Threads - 0of 0 votes
AnswersHow would you access private data member in a class? This class is defined in a library which you cannot modify. There are no friend functions.
- iwanna September 24, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 2 votes
AnswersDifference between a crash and exception.
- avinash September 20, 2014 in India for GTSC
Difference between macros and inline functions.
Mfc: message maps and virtual functions.
Different calling convention.
Late n early binding...
Garbage collector algorithm. When gc will fail to clean the memory.
How to know heap size, crash dump analysis, What is a stack n how to know stack memory size.
Commands in windbg.
Questions on Critical section, mutex, semaphores. Can we use mutex in single process and how?
Working of MSIL and JIT COMPILER.
Can a C# code, use c++ code and call kernel functions like createfile.
Areas: dot net, oops, operating systems, thread synchronization.
Difference in execution steps of c++ and c# code| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Assembly C++ Data Structures Debugging Object Oriented Design Operating System Threads - 5of 5 votes
AnswersGiven three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum
- Greg September 04, 2014 in United States
Please provide as efficient code as you can.
Can you better than this ???| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C++ Coding - 1of 1 vote
AnswersIf you run the same program twice, what section would be shared in the memory?
- farzanmoofty August 12, 2014 in United States for Price history
Follow up, is the text portion of memory share? Why not?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Operating System - 1of 1 vote
AnswersWhat do you do if your program does a core dump?
- farzanmoofty August 12, 2014 in United States for Price history
(Analyze code dump)
Name all the possible ways a program would do core dump.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C C++ Compiler - 0of 0 votes
AnswersWrite a function that accepts an n-dimension array and prints its values--For array of any dimension.
- farzanmoofty August 12, 2014 in United States for Price history
What is the layout of multi-dimensional array in the memory?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Arrays C++ Coding - 1of 1 vote
AnswersGiven a number n, write a function that writes a Fibonacci sequence to number n.
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding - 0of 0 votes
AnswersIt was part of a bigger question --a large piece of code.
- farzanmoofty August 12, 2014 in United States for Price history
Implement << operator. What are the differences of implementation as a member function and a non-member function| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Object Oriented Design - 0of 0 votes
AnswersWhat does an iterator in C++ point to in case of a vector vs. list. Where would it point to if the prior links are deleted in the list? In case of a vector if it points to a specific index, where would it point to if the prior indexes are deleted?
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Arrays C++ Coding Linked Lists - 0of 0 votes
AnswersWhat C++ data structures would you use to implement LRU cache? Show implementation.
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding - 0of 0 votes
AnswersHow would you implement this:
- farzanmoofty August 12, 2014 in United States for Price historyobject["String for a security name"]["another string"] = another_object
| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding