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

SDE

Codenation
upvote
share-icon
4 rounds | 8 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 months
Topics: Data Structures, Algorithms, Database Management Systems, Object Orientated Programming, Operating Systems, Computer Networks
Tip
Tip

Tip 1 : Consistency
Tip 2 : Never Give Up
Tip 3 : Learn from the mistakes

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

Tip 1 : Simple and short providing the required information
Tip 2 : Single page resume with showing all the multiple projects which have done.

Interview rounds

01
Round
Medium
Online Coding Interview
Duration90 minutes
Interview date23 Aug 2021
Coding problem3

The first round consisted of three algorithmic questions conducted on Hacker rank. They were tough questions

1. Alternate Positive and Negative

Easy
15m average time
80% success
0/40
Asked in companies
PayUAmazonDisney + Hotstar

You are given an array ‘arr’ that contains an equal number of positive and negative elements. Rearrange the given array such that positive and negative numbers are arranged alternatively. Also, the respective relative order of positive and negative should be maintained.

For example:

For the given arr[ ] = { -1, 3, 5, 0, -2, -5 } 
arr[ ] = {3, -1, 5, -2, 0, -5 } is valid rearrangement.
arr[ ] = {3, -1, 0, -2, 5, -5 } is invalid rearrangement; order of 0 and 5 is changed. 
arr[ ] = {3, -1, 5, 0, -2, -5 } is invalid rearrangement; positive and negative elements are not alternative.

Note:

Make changes in the same array and no returning or printing is needed.
Consider zero(0) as a positive element for this question.
It is guaranteed that an answer always exists.
Problem approach

First, sort the array in non-increasing order. Then we will count the number of positive and negative integers.
Then swap the one negative and one positive number in the odd positions till we reach our condition.
This will rearrange the array elements because we are sorting the array and accessing the element from left to right according to our need.

Time Complexity: O(N*logN)

Space Complexity: O(1)

Try solving now

2. Product Of Array Except Self

Easy
26m average time
0/40
Asked in companies
FacebookDelhiveryIntuit

You have been given an integer array/list (ARR) of size N. You have to return an array/list PRODUCT such that PRODUCT[i] is equal to the product of all the elements of ARR except ARR[i]

 Note :
Each product can cross the integer limits, so we should take modulo of the operation. 

Take MOD = 10^9 + 7 to always stay in the limits.
Follow up :
Can you try solving the problem in O(1) space?
Problem approach

Create two array prefix and suffix of length n, i.e length of the original array, initialize prefix[0] = 1 and suffix[n-1] = 1 and also another array to store the product.
Traverse the array from second index to end.
For every index i update prefix[i] as prefix[i] = prefix[i-1] * array[i-1], i.e store the product upto i-1 index from the start of array.
Traverse the array from second last index to start.
For every index i update suffix[i] as suffix[i] = suffix[i+1] * array[i+1], i.e store the product upto i+1 index from the end of array
Traverse the array from start to end.
For every index i the output will be prefix[i] * suffix[i], the product of the array element except that element.

Time Complexity: O(n). 
The array needs to be traversed three times, so the time complexity is O(n).
Space Complexity: O(n). 
Two extra arrays and one array to store the output is needed so the space complexity is O(n)

Try solving now

3. K-th Element of 2 Sorted Array

Hard
20m average time
80% success
0/120
Asked in companies
MicrosoftCodenationSigmoid

You're given two sorted arrays 'arr1' and 'arr2' of size 'n' and 'm' respectively and an element 'k'.


Find the element that would be at the 'kth' position of the combined sorted array.


Position 'k' is given according to 1 - based indexing, but arrays 'arr1' and 'arr2' are using 0 - based indexing.


For example :
Input: 'arr1' = [2, 3, 45], 'arr2' = [4, 6, 7, 8] and 'k' = 4
Output: 6
Explanation: The merged array will be [2, 3, 4, 6, 7, 8, 45]. The element at position '4' of this array is 6. Hence we return 6.


Problem approach

Since we are given two sorted arrays, we can use the merging technique to get the final merged array. From this, we simply go to the k’th index.
Divide And Conquer Approach 
While the previous method works, can we make our algorithm more efficient? The answer is yes. By using a divide and conquer approach, similar to the one used in binary search, we can attempt to find the k’th element in a more efficient way.
Compare the middle elements of arrays arr1 and arr2, let us call these indices mid1 and mid2 respectively. Let us assume arr1[mid1] k, then clearly the elements after mid2 cannot be the required element. Set the last element of arr2 to be arr2[mid2].
In this way, define a new subproblem with half the size of one of the arrays.

Time Complexity: O(log n + log m)

Auxiliary Space: O(logn + logm)

Try solving now
02
Round
Easy
Face to Face
Duration90 minutes
Interview date24 Aug 2021
Coding problem1

The second round was based on data structures and puzzles, conducted on skype. He asked me to implement a stack. I implement it using a singly linked list. With the pointer pointing to the end of the linked list. I implemented push, pop operations handling overflow and underflow cases. Initially I was maintaining two pointers but he was not satisfied with it and told me to do it using only one pointer. I implement push and pop functions in O(1). I was asked 5 pirates and 100 gold coins puzzle.

1. 5 Pirates and 100 Gold Coins Puzzle Question

There are 5 pirates, they must decide how to distribute 100 gold coins among them. The pirates have seniority levels, the senior-most is A, then B, then C, then D, and finally the junior-most is E. Rules of distribution are: The most senior pirate proposes a distribution of coins.All pirates vote on whether to accept the distribution.The distribution is approved if at least half of the pirates agree (including the proposer)If the distribution is accepted, the coins are disbursed and the game ends.If not, the proposer is thrown and dies, and the next most senior pirate makes a new proposal to begin the system again.In case of a tie vote, the proposer can have the casting voteRules every pirate follows.Every pirate wants to surviveGiven survival, each pirate wants to maximize the number of gold coins he receives.What is the maximum number of coins that pirate A might get?

Problem approach

The answer is 98 which is not intuitive. 
A uses the facts below to get 98. 

Consider the situation when A, B, and C die, only D and E are left. E knows that he will not get anything (D is senior and will make a distribution of (100, 0). So E would be fine with anything greater than 0.
Consider the situation when A and B die, C, D, and E are left. D knows that he will not get anything (C will make a distribution of (99, 0, 1)and E will vote in favor of C).
Consider the situation when A dies. B, C, D, and E are left. To survive, B only needs to give 1 coin to D. So distribution is (99, 0, 1, 0)
Similarly, A knows about point 3, so he just needs to give 1 coin to C and 1 coin to E to get them in favor. So distribution is (98, 0, 1, 0, 1).

03
Round
Medium
Face to Face
Duration90 minutes
Interview date25 Aug 2021
Coding problem3

this round is also ds and algo and oops, dbms, cn

1. Longest Consecutive Sequence

Moderate
40m average time
70% success
0/80
Asked in companies
AmazonAppleUber

You are given an unsorted array/list 'ARR' of 'N' integers. Your task is to return the length of the longest consecutive sequence.

The consecutive sequence is in the form ['NUM', 'NUM' + 1, 'NUM' + 2, ..., 'NUM' + L] where 'NUM' is the starting integer of the sequence and 'L' + 1 is the length of the sequence.

Note:

If there are any duplicates in the given array we will count only one of them in the consecutive sequence.
For example-
For the given 'ARR' [9,5,4,9,10,10,6].

Output = 3
The longest consecutive sequence is [4,5,6].
Follow Up:
Can you solve this in O(N) time and O(N) space complexity?
Problem approach

The idea is to first sort the array and find the longest subarray with consecutive elements. 
After sorting the array and removing the multiple occurrences of elements, run a loop and keep a count and max (both initially zero). Run a loop from start to end and if the current element is not equal to the previous (element+1) then set the count to 1 else increase the count. Update max with a maximum of count and max.

This problem can be solved in O(n) time using an Efficient Solution. The idea is to use Hashing. We first insert all elements in a Set. Then check all the possible starts of consecutive subsequences.

Algorithm: 

Create an empty hash.
Insert all array elements to hash.
Do following for every element arr[i]
Check if this element is the starting point of a subsequence. To check this, simply look for arr[i] – 1 in the hash, if not found, then this is the first element a subsequence.
If this element is the first element, then count the number of elements in the consecutive starting with this element. Iterate from arr[i] + 1 till the last element that can be found.
If the count is more than the previous longest subsequence found, then update this.


Time complexity: O(nLogn). 
Time to sort the array is O(nlogn).
Auxiliary space : O(1). 
As no extra space is needed.

Try solving now

2. Trapping Rain Water

Moderate
15m average time
80% success
0/80
Asked in companies
RazorpayMorgan StanleyUber

You have been given a long type array/list 'arr’ of size 'n’.


It represents an elevation map wherein 'arr[i]’ denotes the elevation of the 'ith' bar.



Note :
The width of each bar is the same and is equal to 1.
Example:
Input: ‘n’ = 6, ‘arr’ = [3, 0, 0, 2, 0, 4].

Output: 10

Explanation: Refer to the image for better comprehension:

Alt Text

Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Problem approach

Approach: The idea is to traverse every array element and find the highest bars on the left and right sides. Take the smaller of two heights. The difference between the smaller height and height of the current element is the amount of water that can be stored in this array element.
Algorithm: 
Traverse the array from start to end.
For every element, traverse the array from start to that index and find the maximum height (a) and traverse the array from the current index to end, and find the maximum height (b).
The amount of water that will be stored in this column is min(a,b) – array[i], add this value to the total amount of water stored
Print the total amount of water stored.

Try solving now

3. Painter's Partition Problem

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

Given an array/list of length ‘n’, where the array/list represents the boards and each element of the given array/list represents the length of each board. Some ‘k’ numbers of painters are available to paint these boards. Consider that each unit of a board takes 1 unit of time to paint.


You are supposed to return the area of the minimum time to get this job done of painting all the ‘n’ boards under a constraint that any painter will only paint the continuous sections of boards.


Example :
Input: arr = [2, 1, 5, 6, 2, 3], k = 2

Output: 11

Explanation:
First painter can paint boards 1 to 3 in 8 units of time and the second painter can paint boards 4-6 in 11 units of time. Thus both painters will paint all the boards in max(8,11) = 11 units of time. It can be shown that all the boards can't be painted in less than 11 units of time.


Problem approach

We can implement the naive solution using recursion with the following optimal substructure property: 
Assuming that we already have k-1 partitions in place (using k-2 dividers), we now have to put the k-1 th divider to get k partitions. 
How can we do this? We can put the k-1 th divider between the i th and i+1 th element where i = 1 to n. Please note that putting it before the first element is the same as putting it after the last element.
The total cost of this arrangement can be calculated as the maximum of the following: 
a) The cost of the last partition: sum(Ai..An), where the k-1 th divider is 
before element i. 
b) The maximum cost of any partition already formed to the left of the k-1 th divider.
Here a) can be found out using a simple helper function to calculate sum 
of elements between two indices in the array. How to find out b) ? 
We can observe that b) actually is to place the k-2 separators as fairly as 
possible, so it is a subproblem of the given problem.

Try solving now
04
Round
Easy
Face to Face
Duration60 minutes
Interview date26 Aug 2021
Coding problem1

The fourth round was with CEO and it was on Skype. It was HR round.

1. Basic HR Questions

Why do you want to join this company?

What was the toughest problem you have faced?

Here's your problem of the day

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

Skill covered: Programming

What is recursion?

Choose another skill to practice
Similar interview experiences
company logo
SDE - Intern
3 rounds | 3 problems
Interviewed by Codenation
1489 views
0 comments
0 upvotes
company logo
SDE - Intern
4 rounds | 6 problems
Interviewed by Codenation
3448 views
1 comments
0 upvotes
company logo
SDE - Intern
3 rounds | 5 problems
Interviewed by Codenation
0 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 9 problems
Interviewed by Salesforce
3452 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE
3 rounds | 6 problems
Interviewed by PhonePe
0 views
0 comments
0 upvotes
company logo
SDE
5 rounds | 8 problems
Interviewed by Mathworks
1205 views
0 comments
0 upvotes
company logo
SDE
4 rounds | 7 problems
Interviewed by PhonePe
0 views
0 comments
0 upvotes