C++ Interview Questions
- 0of 0 votes
Answersdeadlock detection is an important consideration in operating system of computer.In this problem you will be given a directed graph representing the state of the system.Your program should detect the whether there are any deadlocks in the system(A deadlock can be created by checking for the cycles in the graph
- swetankkanaujiamk March 21, 2020 in United States
the input will be in the form
process X holds sources Ri and wants resources Rj ( X holds the Rj means an edge Ri->X and X wants Rj means an edge X->Rj).Note that both processes and resources form nodes of the graph.
Use depth first traversal to determine whether they are the cycles in the graph.The graph contains a cycle if while expanding a node ,you encounter a child that is represent in the path from the root of the current tree to the node being expanded .You can assume that the maximum number number of nodes in the graph will not exceed 50| Report Duplicate | Flag | PURGE
C++ - 1of 1 vote
AnswersClass A has two data members which are instances of class B and class C. Class B needs an instance of class C to be created. We have to create an instance of object A on stack like 'A objA' in main function. 'new' operator should not be used anywhere.no objects on the heap
- vijay8836 December 18, 2019 in United States| Report Duplicate | Flag | PURGE
Adobe Software Engineer C++ - 0of 0 votes
AnswersQuestion 1:
- ratneshtr09 June 15, 2019 in United States
There is a bunch of tasks, each task has a code with different time to complete and task dependencies. There are few workers, how to allocate the task to these workers to minimize the total time taken to complete the task.
Example:
No of worker: 3
Task id, Task Time, Task dependency:
1, 2, 0
2, 4, 1
3, 7, 0
4, 12, 1
Question 2: Optimize the problem for total project cost and total project days to minimal.
Given the cost/hour of each worker:
[ 30, 25, 40 ]| Report Duplicate | Flag | PURGE
Intel SDE1 C++ - 0of 0 votes
Answer#include <iostream>
- reshma.dhotre November 30, 2018 in India
using namespace std;
int main()
{
int a = 32, *ptr = &a;
char ch = 'A', &cho = ch;
cho += a;
*ptr += ch;
cout << a << ", " << ch << endl;
return 0
}| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer C++ - 1of 1 vote
AnswersThe difference between move and forward in C++
- parni November 01, 2018 in United States| Report Duplicate | Flag | PURGE
Google C++ - 0of 0 votes
AnswerGiven a point and a radius r, draw a circle.
- Wandering programmer September 12, 2018 in United States| Report Duplicate | Flag | PURGE
Pure Storage Software Engineer C C++ - 0of 0 votes
AnswersHow to generate globally unique identifier(GUID)
- coder September 07, 2018 in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer C# C++ - 0of 0 votes
AnswersGiven a singly linked list, write code to find the most frequent element value in the list and its occurrence.
- jp May 18, 2018 in United States
In case of duplicate number of occurrences, return the element value closest to the head.
A solution of time complexity O(N) average is preferred.
Sample Input: 1 2 3 4 2 3 2
Sample Output: Element 2 occurs 3 time(s)
Sample Input: 4 3 5 3 4 5
Sample Output: Element 4 occurs 2 time(s)| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswerA king gathers all the men in the kingdom who are to be put to death for their crimes, but because of his mercy, he will pardon one. He gathers the men into a circle and gives the sword to one man. The man kills the man to his left, and gives the sword to the man to the dead man's left. The last man alive is pardoned.
- Kolloba February 09, 2018 in China
With 5 men, the 3rd is the last man alive.
Write a program that accepts a single parameter: a number N that represents the number of criminals to start with. The program should output the number of the last two men alive.
Example #1: myProgram 5
would output:
5, 3
Example #2: myProgram 7
would output:
3, 7| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersYou are given two numbers L and R, can you count how many number between L and R inclusive their first digit from left equal to one?
- walidmo3geza January 20, 2018 in Egypt| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
Answershow to create an object on the stack.
- Giri February 10, 2017 in India
and also make sure that only 5 objects are created for the class| Report Duplicate | Flag | PURGE
Oracle SDE-2 C++ - 1of 1 vote
Answersn points on a 2D space. You observe the points from (0,0) with viewing direction and viewing angle.
- Casper November 17, 2016 in United States
Given an array (xn,yn), and a viewing angle v (45 degree), find the direction that can observe max number of points.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C++ - 1of 1 vote
AnswersYou are given a sorted list of distinct integers from 0 to 99, for instance [0, 1, 2, 50, 52, 75]. Your task is to produce a string that describes numbers missing from the list; in this case "3-49,51,53-74,76-99".
- Casper November 14, 2016 in United States
Examples:
[] “0-99”
[0] “1-99”
[3, 5] “0-2,4,6-99”| Report Duplicate | Flag | PURGE
Google Software Engineer Intern C++ - 0of 2 votes
AnswerAssume (n+1) points on a 2D space. You observe the points from (0,0) with viewing direction and viewing angle.
- Casper November 14, 2016 in United States
Given an array (xn,yn), and a viewing angle v (45 degree), find the direction that can observe max number of points.| Report Duplicate | Flag | PURGE
Google Software Engineer Intern C++ - 1of 1 vote
AnswersProgram to print string value if each vowel of associated with value 1 and each consonant associated with value 2 print the sum of string value
- Rising star October 10, 2016 in India
Ex if input:a
Print O/p:1
I/p:ab
O/p:1+2=3
I/p:abcd
O/l:1+2+2+2=7
I/p:abcde
O/p1+2+2+2+1=8| Report Duplicate | Flag | PURGE
Amazon Software Developer C++ - 0of 0 votes
AnswersWrite a program to add the following
- D PRAVEEN KUMAR October 04, 2016 in India
¼+2/4+3/4+5/3+6/3+...| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswersWrite a program to get the user name and age
- D PRAVEEN KUMAR October 04, 2016 in India
Condition:
The name should be more than six characters and it shouldn’t contain any other characters than alphabet(like !,@,#,$,^,& these are not to be present)
The age of the employee must between 18-35| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 1of 1 vote
AnswersGet an 0. From user and display it’s prime factor
- D PRAVEEN KUMAR October 04, 2016 in India
Example 24 is 2,2,2,3 and 55 is 5,11| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswersIn a college library fines are issued according to the following condition
- D PRAVEEN KUMAR October 04, 2016 in India
If return books exceeds the due date
Up to 5 days 20rs fine
6-10 days 50rs fine
>10 days 100rs fine
More than 30 days membership will be cancelled
Get the due date from the user and calculate| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswersWrite a program to get a string and to convert the 1st letter of it to uppercase ?
- D PRAVEEN KUMAR October 04, 2016 in India| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswerWrite a program to create a sentence at runtime and count number of vowels in it ?
- D PRAVEEN KUMAR October 04, 2016 in India| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswersWrite a program to calculate the following i want a c++program for this condition 1+4+9+16+….+100
- D PRAVEEN KUMAR October 04, 2016 in India| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
AnswersWrite a class stringOperation to check whether the characters entered by the user are same or not
- D PRAVEEN KUMAR October 04, 2016 in India| Report Duplicate | Flag | PURGE
HTC Global Services Software Developer C++ - 0of 0 votes
Answerswhy we need interface ( pure virtual function or abstract class) in c++?
- sanjay.pu October 03, 2016 in United States
Instead of having abstract class we can have a base class with virtual function defined in it, and override that virtual function in derived class.
what would be the advantage and disadvantage with the above approach ( except we can create the object of the base class)?| Report Duplicate | Flag | PURGE
Alcatel Lucent Software Engineer / Developer C++ - 0of 2 votes
Answerpair programming example question with code for thoughworks interview
- rahulgoyal030 August 16, 2016 in India| Report Duplicate | Flag | PURGE
ThoughtWorks Software Developer C++ - 0of 0 votes
AnswersFind out the output. Or Correct it if something is wrong.
#include <iostream> #include<typeinfo> using namespace std; class base{ public: int a; base():a(0) {} int getA(){return a;} }; class der:public base { public: int b; der():b(1) {} int getB(){return b;} }; void display(base *obj, int ele) { for(int i = 0; i < ele; i++) { cout << (obj+i)->getA() <<endl; } } int main() { int i = 3; base arrb[i]; display(arrb, 3); der arrd[i]; display(arrd, 3); return 0; }
The output is looking like
0 0 0 0 1 0
To me the output should be
0,0,0,0,0,0 //6 0's
But, how come
1
is coming in?
- rasmiranjanbabu July 12, 2016 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Analyst C++ - 0of 0 votes
AnswersOur merchants receive "weekly" invoices, following these rules:
- deepakmr2008 May 02, 2016 in United States
- Each Saturday (00:00 UTC) marks the beginning of a new billing period
- Each 1st of a month (00:00 UTC) marks the beginning of a new billing
period
- Within a year, billing periods are numbered consecutively, starting
with billing period number 1 on Jan 1
Billing periods can therefore be identified by a year and a period
number.
Task:
-----
Write the following functions:
*) For a given date, return the id of the latest period that ends
before this date, e.g.
auto getLatestBillingPeriodId(Date date) -> PeriodId;
*) For a given period id, return the begin and the end date of the
billing period, e.g.
auto getDateRange(PeriodId periodId) -> std::pair<Date, Date>;| Report Duplicate | Flag | PURGE
C++ - 1of 1 vote
AnswersStanford has to select a team of dodgeball players from its class of 2013. There are n students in the class and each student is identified by his/her student ID, which is between 1 and n. The coach has to select K players out of these n students for his team. But there is a twist, if among the K dodgeball players, a player's ID number evenly divides another player's ID number, then there is a high chance of them getting into a fight. The coach will do his best to select the K players so that no pair of players among them will want to fight one another. But if the game turns out to be very popular, this becomes impossible. Complete the function dodgeBall to return the minimum size of K at which it becomes impossible to choose a dodgeball team that has no fighting?
- vick4523zf March 22, 2016 in United States
Input Format:
One line of text, containing the size of the class of 2013, n
Constraints:
1 <= n <= 5,000,000,000
n is guaranteed to be an even number
Output Format:
The minimum size of K that guarantees the existence of 2 players who fight with each other in any K-sized subset of the class.
Sample Input:
4
Sample Output:
3
Explanation:
If the team = {1,2,3}: 1&2 or 1&3 can fight with each other
If the team = {1,3,4}: 1&3 or 1&4 can fight with each other
If the team = {2,3,4}: 2&4 can fight with each other
If K=2, then the teams {3,4} or {2,3} will have no fights. So 3 is the smallest value of K for which any K-sized team, must include a fighting pair.
Sample Input:
2
Sample Output:
2
Explanation:
The team = {1,2}: 1&2 can fight with each other| Report Duplicate | Flag | PURGE
Twitter Software Engineer Intern Algorithm C++ Computer Science
Open Chat in New Window