C++ Interview Questions
- 0of 0 votes
AnswersThe strength of a pair integer sequences is defined by the number of integers that they have in common. You are required to find the strength of several pairs of integer sequences.
- Marey December 10, 2013 in United States for artificial intelligence team
INPUT
The first line of input contains T, the number of test cases. T test cases follow. Each test case contains 3 lines. The first line contains two integers N and M, which are the lengths of the two sequences. The next two lines contain the sequences.
OUTPUT
This should contain T lines, each containing an integer representing the strength of the pair of sequences for the corresponding test case.
CONSTRAINTS
The length of each sequence will be between 1 and 20 inclusive
A sequence can contain an integer between 1 and 100 inclusive
Sequences will not contain duplicate integers
SAMPLE INPUT
3
4 4
1 2 3 4
3 4 5 6
4 5
1 2 3 4
1 2 3 5 6
3 4
1 2 3
5 6 7 4
SAMPLE OUTPUT
2
3
0| Report Duplicate | Flag | PURGE
Achieve Internet Analyst C++ - 0of 0 votes
AnswersThe binary weight of a positive integer is the number of 1's in its binary representation. For example, the decimal number 1 has a binary weight of 1, and the decimal number 7 (which is 111 in binary) has a binary weight of 3.
- Marey December 10, 2013 in United States for artificial intelligence team
Given a positive integer N, find the smallest integer greater than N that has the same binary weight as N.
INPUT
The first line of input contains a number T the number of test cases. The next T lines contain a number N.
OUTPUT
For each test case output a line containing the smallest number greater than N which has the same binary weight as N.
CONSTRAINTS
1 <= N <= 10000
SAMPLE INPUT
2
3
7
SAMPLE OUTPUT
5
11| Report Duplicate | Flag | PURGE
Achieve Internet Analyst C++ - 0of 0 votes
AnswersGiven an integer N, find the smallest integer greater than N which is prime.
- Marey December 10, 2013 in United States for artificial intelligence team
INPUT
The first line of input contains T, the number of test cases. T test cases follow. Each test case contains a single integer N.
OUTPUT
This should contain T lines, each containing the smallest prime integer greater than N.
CONSTRAINTS
1 <= T <= 5
1 <= N <= 100
SAMPLE INPUT
2
6
11
SAMPLE OUTPUT
7
13| Report Duplicate | Flag | PURGE
Achieve Internet Analyst C++ - -1of 1 vote
Answersin C++, Suppose we are creating 2 objects like: "sample *s1 = new sample(); and sample *s2 = new sample(); then in this case what will happen if we do like: *s1 = *s2;" Please provide me the answer in detail
- manojvajpai December 09, 2013 in India for HCT-I| Report Duplicate | Flag | PURGE
GE (General Electric) Senior Software Development Engineer C++ - 0of 0 votes
AnswersHow to find the number of static objects and dynamic objects created for a class?
Let say,class MyClass { public: }; int main() { MyClass cls;//Static Object MyClass *obj = new MyClass();//Dynamic Object ... ... //So on } void NewFun() { MyClass my; MyClass *Obj1; }
It should work for all the cases, like big or small projects
- rasmiranjanbabu November 20, 2013 in United States for Embedded| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Analyst C++ - 0of 0 votes
AnswersHow do you protect your object of your class being deleted by the clients?
- ravi02431 November 13, 2013 in India| Report Duplicate | Flag | PURGE
Tech Lead C++ - 0of 0 votes
AnswersQuestion 3 / 3 (Find first unique character)
- Harjit Singh September 27, 2013 in India for TCS
Find the first unique character in a Stream. Please note that you are being provided a stream as a source for these characters.
The stream is guaranteed to eventually terminate (i.e. return false from a call to the hasNext() method), though it could be very long. You will access this stream through the provided interface methods.
A call to hasNext() will return whether the stream contains any more characters to process.
A call to getNext() will return the next character to be processed in the stream.
It is not possible to restart the stream.
If there is no unique character, then return the character '#'. # won't be any character in the character stream.
You just have to complete the function getUniqueCharacter() using the functions hasNext() and getNext() which are already defined.
Example:
Input:
aAbBABac
Output:
b
Input:
aBBa
Output:
#| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm C++ Data Structures - 2of 2 votes
AnswersQuestion 1 / 3 (Odd even level difference)
- Harjit Singh September 27, 2013 in India for TCS
You are given a function calcDifference which takes in the root pointer of a binary tree as it's input. Complete the function to return the sum of values of nodes at odd height - sum of values of node at even height. Consider the root node is at height 1
Sample Input:
Sample Output
-74
Explanation:
[ (1 + 4 + 5 + 6 + 7 ) ? (2 + 3 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15) = -74 ]| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm C++ Trees and Graphs - 0of 0 votes
Answerswrite a program to print a matrix
- ciitaram September 27, 2013 in India
1 2 3
4 5 6
7 8 9
I need to print like following
1 2 3 6 9 8 7 4 5| Report Duplicate | Flag | PURGE
Developer Program Engineer C# C++ - -2of 2 votes
Answerswe create 2 class A, B and we declare 2 variable in Class B . whatever we do change in Class B i want to reflect in Class A ?? How We can Do???
- viki September 15, 2013 in United States| Report Duplicate | Flag | PURGE
C++ - 5of 5 votes
AnswersA link list contains following elements
struct node{ int data; node* next; node* random; }
Given head of such a linked list write a function who copies such a linked list and returns the head of the new list. So if in the original list first node points to fourth node in random the copy should have the same relation. The random pointer can point to any node including itself and more than two nodes can have random pointer to the same node.
- vik September 13, 2013 in United States
Required time complexity O(n) and no extra space can be used (apart from the newly allocated memory which you will need to create the new list)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ Data Structures - -2of 4 votes
AnswersWrite a thread safe data structure such that there could be only one writer at a time but there could be n readers reading the data. You can consider that incrementing or decrementing a variable is an atomic operation. If more than one threads try to write simultaneously then just select one randomly and let others wait
- vik September 13, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ Data Structures Operating System - -1of 1 vote
AnswerYou are planning a big programming conference and have received many proposals which have passed the initial screen process but you're having trouble fitting them into the time constraints of the day -- there are so many possibilities! So you write a program to do it for you.
- ruby.dhivi August 29, 2013 in India
· The conference has multiple tracks each of which has a morning and afternoon session. · Each session contains multiple talks. · Morning sessions begin at 9am and must finish by 12 noon, for lunch. · Afternoon sessions begin at 1pm and must finish in time for the networking event. · The networking event can start no earlier than 4:00 and no later than 5:00. · No talk title has numbers in it. · All talk lengths are either in minutes (not hours) or lightning (5 minutes). · Presenters will be very punctual; there needs to be no gap between sessions. Note that depending on how you choose to complete this problem, your solution may give a different ordering or combination of talks into tracks. This is acceptable; you don’t need to exactly duplicate the sample output given here.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm C++ - 0of 2 votes
AnswersDLL contains N nodes of string data in each node...how you will find the combined string of the nodes is Palindrome or not....?
- advha August 16, 2013 in United States| Report Duplicate | Flag | PURGE
Goldman Sachs Software Analyst C++ - -1of 1 vote
AnswersIf i create 50 Base Class objects and 50 Derived class Objects, then 50 Base Class Virtual Pointers and 50 Derived class virtual pointers created or Static virtual pointer is created one in Base and one in Derived.....?
- advha August 16, 2013 in United States| Report Duplicate | Flag | PURGE
Goldman Sachs Software Analyst C++ - -1of 1 vote
AnswersHow do you dynamically allocate memory for an integer array of 10 bytes?
- rasmiranjanbabu August 11, 2013 in India| Report Duplicate | Flag | PURGE
HCL Software Engineer / Developer C++ - 0of 0 votes
AnswersWhich one you prefer and why?
- yogi.rulzz July 23, 2013 in India
Vector of pointer,reference and object. which one you will prefer.| Report Duplicate | Flag | PURGE
Akamai SDE-2 C++ - 6of 12 votes
AnswersGiven a list of integers, find out the biggest interval that has all its members in the given list. e.g. given list 1, 7, 4, 6, 3, 10, 2 then answer would be [1, 4]. Develop algorithm and write code for this
- prongs July 08, 2013 in India| Report Duplicate | Flag | PURGE
Google Applications Developer Algorithm Arrays C++ Coding - 0of 0 votes
AnswersWrite code to clone a graph recursively
- prongs July 08, 2013 in Indiastruct Node { int data; vector<struct Node*> neighbors; }
| Report Duplicate | Flag | PURGE
Google Applications Developer Algorithm C++ Coding - 0of 0 votes
AnswersImplement (in C++, MATLAB, or Java) a Fraction class that supports the following operations: addition, subtraction, multiplication, division, equality/non-equality, greater than/less than, and display. The program should take on the order of several hours. If there are techniques that would take longer to implement, note it down as comments.
- AnOnYmOuS June 24, 2013 in India| Report Duplicate | Flag | PURGE
Algorithm C++ Coding Java Math & Computation - 1of 1 vote
AnswersTwo files containing large number, one in each. You have only fopen(), int read(fp), fclose(), fwrite(). Add these two numbers and write in third file with the help of given functions only.
- grave June 23, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm C# C++ Coding Data Structures - -1of 1 vote
AnswersIs this even possible? Move the spaces to the starting of the string in a c style string. In place within one iteration.
- madzig June 14, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ - 0of 0 votes
Answershow to solve this ((3000000!)/(30!)^100000)%(any prime no.) in C++
- 3139a1m June 14, 2013 in India| Report Duplicate | Flag | PURGE
Adobe Intern C++ - -5of 7 votes
Answersneed to implement a weather report functionality. user will provide the city name , need to return the weather report.
- gopi.komanduri May 29, 2013 in India
if weather station exists n functioning properly , will return the weather report of that station .
else ,
will return the nearest available weather station report.
interviewer looking for optimized manner.
looking for datastructures to stores the cities n algo to return the report.| Report Duplicate | Flag | PURGE
Mentor Graphics Analyst Algorithm Arrays Bit Manipulation Brain Teasers C C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming General Questions and Comments Graphics Hash Table Ideas Linked Lists Math & Computation Object Oriented Design Problem Solving Sets Sorting Stacks String Manipulation Terminology & Trivia Threads Trees and Graphs XML - 3of 3 votes
Answerswhich data structure should be used to implement thread pool ? How to assign particular thread from thread pool ?
- sumit kumar May 22, 2013 in India| Report Duplicate | Flag | PURGE
Senior Software Development Engineer C++ - 0of 0 votes
AnswersSuppose there is a directory XYZ having too many files (100 to 10000). Each file contain the format like first line having company name and second line some data values. We need to read each files in directory and create the new directories at some path with company names and move that file (1.txt ) to that directory.
- sumit kumar May 22, 2013 in United States
what should be design.
My suggestion was to Create a function ScanDir() which will read the count of files and will make loop to read the file and will create a thread for that file and move to next file and process the all files.| Report Duplicate | Flag | PURGE
Senior Software Development Engineer C++ - 0of 2 votes
AnswersGiven a circular linked list, find the mid element of the linked list.
- nightingale May 17, 2013 in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++ - 0of 0 votes
Answerswhat is the difference?
- holmespanda May 14, 2013 in United States
void test(vector<int> vec)
{
//ptint the vec;
}
void test(const vector<int> &vec)
{
//print the vec;
}| Report Duplicate | Flag | PURGE
Yelp Analyst C++