Technical Round(1 hr): C++ problems asked in this round
- C++ Output-Based problems:
C++
class
Base{
public
:
Base(){
cout<<
"base called "
;
}
};
class
Derived{
Base b;
public
:
Derived(){
cout<<
"derived called\n"
;
}
};
int
main(){
Derived d;
return
0;
}
What will be the output and why?
- new and delete concept related problem. Print output in below code
C++
class
Derived {
int
id;
public
:
Derived(
int
id)
{
this
->id = id;
cout <<
"derived const for id:"
<< id;
}
~Derived() { cout <<
"derived dest. for id"
<< id; }
};
int
main()
{
Derived d(5);
Derived* d1 =
new
Derived(10);
delete
d1;
return
0;
}
- Override concept related question
C++
class
Base{
public
:
void
show(
int
x){
cout<<
"base called x="
<<x<<endl;
}
};
class
Derived:
public
Base{
public
:
void
show(
float
x){
cout<<
"derived called x="
<<x<<endl;
}
};
int
main(){
Derived d;
d.show(10);
//which func. will be called?
d.Base::show(10);
//also asked to write code to call to Base class show func.
return
0;
}
- Ref concept related problem. Complete following code, so that instance of class A can be created correctly.
C++
class
A {
int
& m_ref;
};
int
main() {
A a;
return
0;
}
- We need to create our own string class, which should behave similar to c++ string class. Write all necessary constructors and destructor for that.
- Also asked when initialization list should be used and when not?
- What’s the need to move semantics?
- https://medium.com/swlh/write-your-own-c-stl-string-class-e20113a8de79
Technical Round 2 (1hr 30 mins):
- Empty class concept program. Will below prog. work fine?
C++
class
A {
};
int
main()
{
A a1;
A* a2=
new
A();
// as size of empty class object is 1
// byte. So, it should be deallocated also
return
0;
}
- Given an array and k. find minimum no. of corner elements required to make their sum=k
arr[]={1,2,3,4,6,2,3,1} k=6
ans=3
First told brute force approach of backtracking. O(pow(2,n));
I provided solution similar to approach discussed here: https://www.geeksforgeeks.org/maximize-sum-of-k-elements-in-array-by-taking-only-corner-elements/amp/
- https://leetcode.com/problems/course-schedule-ii/
Asked about space and time complexity.
https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/amp/
Also, asked about dif. b/w BFS and DFS
Technical Round 3 (1 hr):
- https://www.geeksforgeeks.org/sort-array-converting-elements-squares/amp/. Told optimised approach to solve this
-
https://www.geeksforgeeks.org/check-if-a-word-exists-in-a-grid-or-not/amp/ I solved it using visited array. Interviewer asked about space and time complexity.
I told time complexity->(n*m)^2,
space complexity->n*m due to visited matrix. Asked to solve problem without using visited matrix.
- Asked about lamda expressions.
Asked If I do know about callback, in my company projects, if I have ever used callback.
Then he asked to complete a class implementation
C++class
SignalDispatcher{
public
:
//callbackFunc is lamda expr of format [](mystrut data){}
void
on(string eventName, std::function<
void
(mystruct)> callbackFunc)
//call all callbacks with this eventname and put data as argument
void
trigger(string eventName, mystrut data)
};
Told hashmap and vector approach to store callbacks and then call them
Also, asked to tell unit test cases for this code.
- Implement own generic vector class with 3 funcs push_back(), pop_back(), size()
Managerial Round 1 (~1hr 20 mins):
- Write a macro to find max of 3 numbers.
Asked about pros and cons of Macros. https://www.geeksforgeeks.org/macros-vs-functions/amp/
considering cons of macros, is there any other way to skip context switching? inline functions
- Output based problem
C++
int
a[6] = {0, 1, 2, 3, 4, 5};
cout<<a[0];
cout<<1[a];
cout<<*(a+2);
cout<<*(3+a):
cout<<*a+4;
cout<<a[-1];
cout<<a[6];
- What is Little Endian and big endian. Write program to check endianess of machine https://www.geeksforgeeks.org/little-and-big-endian-mystery/amp/
- Asked if I am familiar with bitwise operator. How to check if number is even or odd?
- Asked about which design patterns I have used? explain observer design pattern.
- Design class structure of snake and ladder game. Cross questions on space and time complexity
Managerial Round 2 (~1 hr):
-
https://www.geeksforgeeks.org/reverse-words-in-a-given-string/amp/
first told stack-based approach and then reduced space complexity to O(1)
-
https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/amp/
As I told about using map, asked about map internal implementation. I told that and then asked to write code for put() and get() api.
I write code without managing height, interviewer asked to write that as well, I was not able to do that.
Also discussed on unordered_map and difference b/w both of them
Director Round (~30 mins):
- Asked about my projects. Lots of discussion on my company’s project.
- Asked to design system in which pdf files can be shared among multiple users and can be edited at same time by multiple users.
Final Verdict: Selected