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

SDE - 1

Flipkart limited
upvote
share-icon
1 rounds | 3 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 3 months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

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

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Hard
Online Coding Test
Duration90 Minutes
Interview date16 Dec 2015
Coding problem3

I found the online coding round of Flipkart to be quite difficult based on the constraints of the problem and their time limits. I coded the first problem quite easily but on the second and the third problem , my code could only pass a few test cases and gave TLE for most of them. Both the questions required very efficient solution and the last 5 to 10 Test Cases carried more weight than the rest so I didn't get through this round.

Easy
15m average time
85% success
0/40
Asked in company
Flipkart limited

You are given three non-negative integers N, M, and K. Your task is to print the Kth digit from the right in ‘N’ raised to the power ‘M’ that is, in N ^ M.

Note:

1) It is guaranteed that the Kth digit from the right always exists.
2) It is also guaranteed that 'K' is always less than or equal to the number of digits in N ^ M.
3) 'N' and 'M 'can’t be a 0 simultaneously.
Problem approach

The idea here is to use the pow function to find N raised to the power M. After finding the power, we start removing the digits from the last until we get the kth digit.

 

  • Create a long long int variable to store the power named as temp. Note that the value of N and M can go up to 15, which means N^M may not fit in the int. So, we have created a long long int type variable.
  • Make temp = pow(N,M).
  • Create an int variable to store the current digit place from the right named as cnt. Initialize it to 0.
  • Create an int variable called ans to store the answer. Initialize it to 0.
  • Run a while loop till temp > 0, here we are planning to iterate through the digits of the temp from right to left by using %10 (temp % 10 will give the last digit of temp) :
    • Find the last digit, lastDigit = temp % 10.
    • Increment the cnt by 1.
    • If cnt == K, which implies that we are at the Kth digit so, set ans equal to lastDigit and break the while loop:
    • Otherwise, we have to remove the last digit. So, just divide temp by 10,    temp /= 10.
  • Finally, return the variable ans.
Try solving now

2. The Skyline Problem

Hard
15m average time
85% success
0/120
Asked in companies
UberAppleSamsung R&D Institute

You are given 'N' rectangular buildings in a 2-dimensional city. Your task is to compute the skyline of these buildings, eliminating hidden lines return the skyline formed by these buildings collectively. A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. The geometric information of each building is given in the array of buildings where BUILDINGS[i] = [LEFT_i, RIGHT_i, HEIGHT_i]:

-> LEFT_i is the x coordinate of the left edge of the ith building.

-> RIGHT_i is the x coordinate of the right edge of the ith building.

-> HEIGHT_i is the height of the ith building.

You may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.

The skyline should be represented as a list of "key points" sorted by their x-coordinate in the form [[x1, y1], [x2, y2], ...]. Each key point is the left endpoint of some horizontal segment in the skyline except the last point in the list, which always has a y-coordinate 0 and is used to mark the skyline's termination where the rightmost building ends. Any ground between the leftmost and rightmost buildings should be part of the skyline's contour.

Note:
There must be no consecutive horizontal lines of equal height in the output skyline. For instance, [...,[2 3], [4 5], [7 5], [11 5], [12 7],...] is not acceptable; the three lines of height 5 should be merged into one in the final output.

As such: [..., [2 3], [4 5], [12 7],...]. 

Also, the buildings are sorted by a non-decreasing order.

For more clarification see sample case 1.
Problem approach

Approach (Naive): 

1) Store the coordinates and heights of the buildings paired up with each other with the first building coordinate paired after taking negative of the height and the second coordinate with positive height in a list ‘POINTS’.

2) Now, sort edges present in the ‘POINTS’ list (array) in ascending order.

3) The positions are now sorted from left to right, small to large. Now, initialise a dictionary named 'HEIGHTS' with zero as its first key, having a value of 1 since this would be the last height that would be added.

4) Now, for each pair of an edge in the ‘POINTS’ list (array) and check:
4.1) Update the dictionary if the current edge is a start edge (with negative height) increment the value 
of the key by 1.
4.2) Delete the invalid buildings from the dictionary if an end edge is encountered for a key after 
decrementing its value by 1.
4.3) Now, In each iteration update the 'SKYLINE', which records the highest building from some 
position, and add it to the final list of our 'SKYLINE's if the current highest is no longer the tail of the 
'SKYLINE' (previous highest).

5) We finally return the 'SKYLINE' list (array) that we have formed.


In the test , I could only figure out a O(N^2) solution and hence it gave TLE in the last 5 Test Cases. I later found out a O(N*log(N)) solution which could have passed all the test cases.


Approach (Efficient) :

1) Sort edges with [POSITION, -HEIGHT, VALID_UNTIL]. Here, the first two elements are for iterating edges with the correct sequence, while, the last one is for popping out invalid buildings during the iteration.

2) The positions are now sorted from left to right, small to large.

3) When positions are overlapped, sort the height from high to low, large to a small image

4) Now, for each edge:
4.1) Pop-out invalid buildings from the top of the heap (there might still exist invalid ones in the heap, but 
we just want to make sure the top of the heap is valid).
4.2) And update the heap if the current edge is a start edge
4.3) In each iteration update the 'SKYLINE', which records the highest building from some position, if the 
current highest is no longer the tail of the 'SKYLINE' (previous highest).

5) We finally return the 'SKYLINE' list (array) that we have formed.

Try solving now

3. Longest Palindromic Substring

Moderate
20m average time
80% success
0/80
Asked in companies
MathworksLivekeeping (An IndiaMART Company)Goldman Sachs

You are given a string 'str' of length 'N'.


Your task is to return the longest palindromic substring. If there are multiple strings, return any.


A substring is a contiguous segment of a string.


For example :
str = "ababc"

The longest palindromic substring of "ababc" is "aba", since "aba" is a palindrome and it is the longest substring of length 3 which is a palindrome. 

There is another palindromic substring of length 3 is "bab". Since starting index of "aba" is less than "bab", so "aba" is the answer.
Problem approach

Approach :
1) Create a 2-D dp boolean vector(with all false initially) where dp[i][j] states whether s[i...j] is a palindrome or not and
initilialise a variable ans=1 which will store the final answer.

2) Base Case : For every i from 0 to n-1 fill dp[i][i]=1 ( as a single character is always a palindrome ) .

3) Now, run 2 loops first one from i=n-1 to i=0 (i.e., tarverse from the back of the string) and the second one from
j=i+1 to n .

4) For every s[i]==s[j] , check if(j-i==1 i.e., if s[i] and s[ j] are two consecutive same letters) or if(dp[i+1][j-1]==1 or not
i.e., if the string s[i+1,....j-1] is palindrome or not .

5) Because if the string s[i+1,....j-1] is a palindrome and s[i]==s[j] then s[i] and s[j] can be appended at the starting
and the ending position of s[i+1,...j-1] and s[i...j] will then be a palindrome , so mark dp[i][j]=1 and update the answer
as ans=max(ans , j-i+1).

6) Finally return the ans

TC : O(N^2) where N=length of the string s
SC : O(N^2)

In this question too , my code could only pass a few Test Cases . The constraints were quite tight.
I later found out that there is also a O(N) approach to this problem using Manacher's Algorithm but it was quite complex.

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
SDE - 1
3 rounds | 10 problems
Interviewed by Flipkart limited
2634 views
0 comments
0 upvotes
SDE - 1
3 rounds | 7 problems
Interviewed by Flipkart limited
1189 views
0 comments
0 upvotes
SDE - 1
3 rounds | 3 problems
Interviewed by Flipkart limited
1718 views
0 comments
0 upvotes
SDE - 1
3 rounds | 4 problems
Interviewed by Flipkart limited
2197 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
58237 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35146 views
7 comments
0 upvotes