# Nvidia Interview Experience for SDE-2

• Difficulty Level : Hard
• Last Updated : 16 Jan, 2022

Round 1 (Technical Interview) – Three coding questions were asked along with some C++ output questions.

1. https://www.geeksforgeeks.org/pairwise-swap-elements-of-a-given-linked-list/ – I was asked to scale the implemented logic for k > 2.  ( Similar to this question: https://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/)
2. https://www.geeksforgeeks.org/kth-largest-element-in-bst-when-modification-to-bst-is-not-allowed/
3. https://leetcode.com/problems/keys-and-rooms/
4. C++ output questions were asked based on constructor and destructor.

Round 2 (Logical Interview) – Some mathematical questions were asked to check the logical ability.

1. In a group of 7 boys and 5 girls, four children are to be selected. Find the number of ways that they can be selected such that at least one boy is always there.
2. Two dice are rolled together. Find the probability of getting a difference of 1 between the numbers that show up on the dice.
4. Asked to get the time complexity of below function. Check if it can be optimized, if yes then get the time complexity of the optimized function.

## C++

 `unsigned ``int` `power( unsigned ``int` `x, unsigned ``int` `n) {``    ``if``(n == 0) ``return` `1;``    ``if``(n%2 == 0) ``return`  `power(x,n/2) * power(x,n/2);``    ``else` `return`  `x * power(x,n/2) * power(x,n/2);``}`

Round 3 (Technical Interview) –

1. 4D tensor stored in 1D array : Convert NCHW -> NHWC
Input:    N=1, C=3, H=2, W=2 -> 1 2 3 4 5 6 7 8 9 10 11 12
Output: N=1, H=2, W=2, C=3 -> 1 5 9 2 6 10 3 7 11 4 8 12
2. https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/
3. https://www.geeksforgeeks.org/design-a-stack-that-supports-getmin-in-o1-time-and-o1-extra-space/
4. Implement align_Malloc(int size, int align) such that it accepts number of bytes to be allocated and alignment.  Ex: if align = 10, and malloc function returns address 123, then return either 120 or 130.
6. Puzzle: There is a tennis tournament of 128 players. They share a transitive property among themselves, if A beats B, B beats C then A will beat C. Find out the min number of matches required to get the best and second best player among 128. [Main focus was to get the second best player]

Round 4 (Technical  + Behavioral Interview)

1. I was asked about my projects of which I am proud of. Then they ask about the challenges I faced, what I learnt etc.
2. Some C++ output questions were asked based on virtual function concept and copy constructor concept.
3. https://www.geeksforgeeks.org/swap-two-numbers-without-using-temporary-variable/
4. Write a multi threaded C code with one thread printing all even numbers and the other all odd numbers. The output should always be in sequence i.e.. 0,1,2,3,4….etc.
[ https://gist.github.com/jmurudi/7a2fc49e855cb0b308d19f277c7e12b7 ] – interviewers wanted to check the concept of multi-threading, mutex, condition variable etc.

Round 5 (Technical  + Behavioral Interview)

1. Some questions on my projects were asked – roles and responsibilities, what you learnt, any improvement or modification done from your side etc.
2. Difference between mutex and semaphore as some of my projects were based on multi-threading.
3. What issue can occur if two threads are trying to access the same resource? -> I answered about the undefined behavior, order of execution can results differently. Asked to explain some example.
Then I was asked to think of any other issue. -> Deadlock can occur.