# Synopsys Interview Experience | 4 Years Experienced

**Screening Round with Hiring Manager(1hr 30 mins):**

- Asked about current company projects and coding lang. On which I have worked. C++ experience is very imp. for them.
- How do you rate yourself in C++, beginner/intermediate/excellent? I said intermediate
- Diff b/w malloc and new which lead to a discussion on Constructors. Write syntax for copy constructor. Why argument to copy constructor is passed as ref?
- https://www.geeksforgeeks.org/merge-3-sorted-arrays/. 1st told merging approach using 2 arrays at once. But that needs more extra space. So, the interviewer asked to reduce space complexity to O(1). Then, told approach to use an extra array of size 3. Working code was required.
- https://www.geeksforgeeks.org/puzzle-9-find-the-fastest-3-horses/
- https://www.geeksforgeeks.org/count-set-bits-in-an-integer/
- https://www.geeksforgeeks.org/detect-loop-in-a-linked-list/
- https://www.geeksforgeeks.org/puzzle-set-35-2-eggs-and-100-floors/
- https://www.geeksforgeeks.org/maximum-sum-path-across-two-arrays/

I told the approach of using trees/graphs and then check for each possibility but was not able to write code. The interviewer told me the correct approach and ended the interview.

**Technical Round(1 hr):**

- Asked about current company projects.
- Asked if I have worked on C++11 features like move constructor, smart pointers, etc. I told I have not worked, but I have some idea about them
- Difference b/w memory mgmt using malloc and new
- Given 2 linked list which contains single digit data, both have the same length. Discussion on diff. Approaches to add 2 linked list
L1 : 3 -> 5 -> 7 L2 : 4 -> 4 -> 5 L3 : 8 -> 0 -> 2 add (L1, L2)

- I told approach to reverse the linked list and then perform addition, then he added constraint that the linked list can’t be modified
- I told approach to do it using recursion, As it had space complexity of O(n) for stack calls, he asked to do it in const space
- He gave a hint that if the sum of 2 digits<=8 then that it won’t propagate carry backward. so, maintain 2 prev pointers, pointing to nodes such that their sum<=8 and 2 curr pointers if curr pointers sum is >=10, then from prev to curr, we need to propagate carry. He asked to traverse input list nodes only once
- The approach was we need to maintain ptr of latest sum node with sum<=8 and as soon as sum>=10, it means from prev to curr node, all sum nodes are zero.

https://www.geeksforgeeks.org/add-the-given-digit-to-a-number-stored-in-a-linked-list/ -> extension of this problem

**Technical Round(2 hr):**

- Asked about current company projects.
- What are the virtual function and its internal implementation?
- Output-based question
## C++

`class`

`A{`

`int`

`a;`

`public`

`:`

`void`

`show(){`

`cout<<`

`"show"`

`;`

`}`

`void`

`show1(){`

`cout<<`

`"show1:"`

`<<a;`

`}`

`};`

`int`

`main() {`

`A* ptr=NULL;`

`a->show();`

`//will program crash-?`

`a->show1();`

`//will program crash-?`

`return`

`0;`

`}`

He asked the reason also.

- Asked to implement BST(insert, print) in C++. I implemented with funcs. Then he asked to implement it using C++ features of encapsulation and abstraction. I kept Node struct outside my Tree class. He asked to put it inside Tree class and asked about inner classes. Then he asked to make it generic, I did that. Further, he asked to define own DS(having 2 ints) for tree node, many modifications were required for that in code. added operator overloading code for comparison b/w MyDS objects. But print function also needs to be corrected. For that friend function was required. He asked me to take help from Google.
- https://www.geeksforgeeks.org/puzzle-21-3-ants-and-triangle //in my case instead of the triangle it was square
- http://www.crazyforcode.com/3-mislabeled-jars/
- Asked about Tree problem, discussed why we are returning ostream from friend function.
- Then behavioral question why you want to switch. I also told about synopsys.

**Director Round(30 mins): **General discussion about work and work culture