Nagarro Software interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

Nagarro Software
upvote
share-icon
2 rounds | 7 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 months
Topics: Data Structures, DBMS , OOPS, System Design, Algorithms, Dynamic Programming.
Tip
Tip

Tip 1 : Practice At least 250 Questions of DS algo
Tip 2 : Do at least 2 application based projects
Tip 3 : Practice questions with optimized approaches

Application process
Where: Campus
Eligibility: 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have some applicayion based projects on resume.
Tip 2 : Do not put false things on resume.
Tip 3 : Project should clear and crisp

Interview rounds

01
Round
Medium
Online Coding Interview
Duration240 Minutes
Interview date16 Sep 2021
Coding problem5

Aptitude questions + 3 medium level Coding Problem + 2 hard level Coding problem

1. Minimum steps to reach target by a Knight

Moderate
25m average time
60% success
0/80
Asked in companies
MicrosoftIntuitGroww

You have been given a square chessboard of size ‘N x N’. The position coordinates of the Knight and the position coordinates of the target are also given.

Your task is to find out the minimum steps a Knight will take to reach the target position.

alt text

Example:
knightPosition: {3,4}
targetPosition: {2,1}

alt text

The knight can move from position (3,4) to positions (1,3), (2,2) and (4,2). Position (4,2) is selected and the ‘stepCount’ becomes 1. From position (4,2), the knight can directly jump to the position (2,1) which is the target point and ‘stepCount’ becomes 2 which is the final answer. 

Note:

1. The coordinates are 1 indexed. So, the bottom left square is (1,1) and the top right square is (N, N).

2. The knight can make 8 possible moves as given in figure 1.

3. A Knight moves 2 squares in one direction and 1 square in the perpendicular direction (or vice-versa).
Try solving now

2. Reverse Alternate K nodes

Easy
10m average time
90% success
0/40
Asked in companies
AdobeIntuitSalesforce

You are given a Singly Linked List of integers and a positive integer 'K'. Modify the linked list by reversing every alternate 'K' nodes of the linked list.

A singly linked list is a type of linked list that is unidirectional, that is, it can be traversed in only one direction from head to the last node (tail).
Note:
If the number of nodes in the list or in the last group is less than 'K', just reverse the remaining nodes. 
Example:
Linked list: 5 6 7 8 9 10 11 12
K: 3 

Output: 7 6 5 8 9 10 12 11

We reverse the first 'K' (3) nodes and then skip the next 'K'(3) nodes. Now, since the number of nodes remaining in the list (2) is less than 'K', we just reverse the remaining nodes (11 and 12). 
Note:
You need to reverse the first 'K' nodes and then skip the 'K' nodes and so on. 5 6 7 10 9 8 11 12 is not the correct answer for the given linked list. 
Problem approach

Recursively traverse the linked list. When returning from each recursive call keep track of the node number, considering the last node as number 1, second last as number 2 and so on. This counting could be tracked with the help of a global or pointer variable. With the help of this count variable, print the nodes having a node number less than or equal to k.

Try solving now

3. K Sum Subset

Hard
45m average time
50% success
0/120
Asked in companies
ShareChatEPAM SystemsCodenation

You are given an array ‘arr’ of size ‘N’ and an integer ‘K’. Your task is to find the maximum subset-sum of the array that is not greater than ‘K’.

For Example:
Your are given ‘arr’ = [1, 3, 5, 9], and ‘K’ = 16, we can take the subset of elements [9, 5 ,1] which sums up to 15. Hence the answer is 15.
Problem approach

We can solve this problem by computing modulo of array numbers with K. if sum of two numbers is divisible by K, then if one of them gives remainder i, other will give remainder (K – i). First we store frequencies of numbers giving specific remainder in a frequency array of size K. Then we loop for all remainders i and include max(f[i], f[K – i]). Why? a subset with no pair sum divisible by K must include either elements with remainder f[i] or with remainder f[K – i]. Since we want to maximize the size of subset, we pick maximum of two sizes. 
In below code array numbers with remainder 0 and remainder K/2 are handled separately. If we include more than 2 numbers with remainder 0 then their sum will be divisible by K, so we have taken at max 1 number in our consideration, same is the case with array numbers giving remainder K/2.

Try solving now

4. 0 1 Knapsack

Easy
15m average time
85% success
0/40
Asked in companies
DelhiveryTwitterWalmart

A thief is robbing a store and can carry a maximal weight of W into his knapsack. There are N items and the ith item weighs wi and is of value vi. Considering the constraints of the maximum weight that a knapsack can carry, you have to find and return the maximum value that a thief can generate by stealing items.

Problem approach

This question is a type of 0-1 knapsack problem.

In the Dynamic programming we will work considering the same cases as mentioned in the recursive approach. In a DP[][] table let’s consider all the possible weights from ‘1’ to ‘W’ as the columns and weights that can be kept as the rows. 
The state DP[i][j] will denote maximum value of ‘j-weight’ considering all values from ‘1 to ith’. So if we consider ‘wi’ (weight in ‘ith’ row) we can fill it in all columns which have ‘weight values > wi’. Now two possibilities can take place: 

Fill ‘wi’ in the given column.
Do not fill ‘wi’ in the given column.
Now we have to take a maximum of these two possibilities, formally if we do not fill ‘ith’ weight in ‘jth’ column then DP[i][j] state will be same as DP[i-1][j] but if we fill the weight, DP[i][j] will be equal to the value of ‘wi’+ value of the column weighing ‘j-wi’ in the previous row. So we take the maximum of these two possibilities to fill the current state

Try solving now

5. Complete String

Hard
40m average time
60% success
0/120
Asked in companies
SprinklrAdobeBNY Mellon

Ninja developed a love for arrays and strings so this time his teacher gave him an array of strings, ‘A’ of size ‘N’. Each element of this array is a string. The teacher taught Ninja about prefixes in the past, so he wants to test his knowledge.

A string is called a complete string if every prefix of this string is also present in the array ‘A’. Ninja is challenged to find the longest complete string in the array ‘A’.If there are multiple strings with the same length, return the lexicographically smallest one and if no string exists, return "None".

Note :
String ‘P’ is lexicographically smaller than string ‘Q’, if : 

1. There exists some index ‘i’ such that for all ‘j’ < ‘i’ , ‘P[j] = Q[j]’ and ‘P[i] < Q[i]’. E.g. “ninja” < “noder”.

2. If ‘P’ is a prefix of string ‘Q’, e.g. “code” < “coder”.
Example :
N = 4
A = [ “ab” , “abc” , “a” , “bp” ] 

Explanation : 

Only prefix of the string “a” is “a” which is present in array ‘A’. So, it is one of the possible strings.

Prefixes of the string “ab” are “a” and “ab” both of which are present in array ‘A’. So, it is one of the possible strings.

Prefixes of the string “bp” are “b” and “bp”. “b” is not present in array ‘A’. So, it cannot be a valid string.

Prefixes of the string “abc” are “a”,“ab” and “abc” all of which are present in array ‘A’. So, it is one of the possible strings.

We need to find the maximum length string, so “abc” is the required string.
Try solving now
02
Round
Easy
Face to Face
Duration30 minutes
Interview date24 Sep 2021
Coding problem2

The interviewer asked me questions from DS algo. Questions were like tell me the time complexity of this code. I was also asked questions from my projects and some questions from DBMS. 
2 coding questions were given to me to solve

1. Count derangements

Moderate
25m average time
75% success
0/80
Asked in companies
MicrosoftMAQ SoftwareLTI - Larsen & Toubro Infotech

Given a number ‘N', the task is to find the total number of derangements of a set of ‘N’ elements.

A ‘Derangement’ is a permutation of 'N' elements, such that no element appears in its original position. For example, a derangement of {0, 1, 2, 3} is {2, 3, 1, 0}.

For example, 'N' = 2 , {0, 1} and {1, 0} are the only derangement therefore output will be 1.

Problem approach

There are n – 1 way for element 0 (this explains multiplication with n – 1). 
Let 0 be placed at index i. There are now two possibilities, depending on whether or not element i is placed at 0 in return. 

i is placed at 0: This case is equivalent to solving the problem for n-2 elements as two elements have just swapped their positions.
i is not placed at 0: This case is equivalent to solving the problem for n-1 elements as now there are n-1 elements, n-1 positions and every element has n-2 choices

Try solving now

2. Coin game winner where every player has three choices

Moderate
25m average time
75% success
0/80
Asked in companies
OlaNagarro Software

Two players 'X' and 'Y', are playing a coin game. Initially, there are 'N' coins. Each player can pick exactly 'A' coins or 'B' coins or 1 coin. A player loses the game if he is not able to pick any coins. 'X' always starts the game, and each player plays optimally. You are supposed to find which player wins the coin game.

Problem approach

The idea is to use a dynamic programming paradigm, and see who wins the game. ‘X’ start’s the game and has 3 options, to choose ‘A’ or ‘B’ or 1 coin. Similarly, ‘Y’ makes a move and so on. The player who is not able to move further loses the coin game. We solve in a bottom-up manner from 0 to 'NO_OF_COINS' coins and calculate our ans.

Let’s say if we have some i coins, and Player ‘X’ is playing the game, ‘X’ will always try to reach a point from where ‘Y’ cannot win. So, we are checking all three options, we can reach a point from where the other player cannot win we return true otherwise we return false.



The algorithm is as follows :

Declare a boolean array ‘DP’, where DP[i] stores the player starting with ‘i’ coins wins the game or not, if the player starting with ‘i’ coins wins it stores true, otherwise false.
Set, DP[0] to false.
Set, DP[1] to true.
Iterate from ‘i’ = 2 to ‘N’,
Set, DP[i] to ans to true if DP[i - 1] is false.
If ‘i’ >= ‘A’, set DP[i] to true if DP[i - A] is false.
If ‘i’ >= ‘B’, set DP[i] to true if DP[i - B] is false.
Return, DP[N].

Try solving now

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

How do you remove whitespace from the start of a string?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
3 rounds | 3 problems
Interviewed by Nagarro Software
0 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Nagarro Software
937 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Nagarro Software
1222 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Nagarro Software
758 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
115097 views
24 comments
0 upvotes
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
58238 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35147 views
7 comments
0 upvotes