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

SDE - 1

Walmart
upvote
share-icon
4 rounds | 8 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
Medium
Online Coding Test
Duration60 Minutes
Interview date21 May 2015
Coding problem2

There were 2 coding questions given in this round. One was related to Dynamic Programming and the second one was related to Recursion and Number Theory.

1. House Robber

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

Mr. X is a professional robber planning to rob houses along a street. Each house has a certain amount of money hidden.


All houses along this street are arranged in a circle. That means the first house is the neighbour of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses are broken into on the same night.


You are given an array/list of non-negative integers 'ARR' representing the amount of money of each house. Your task is to return the maximum amount of money Mr. X can rob tonight without alerting the police.


Note:
It is possible for Mr. X to rob the same amount of money by looting two different sets of houses. Just print the maximum possible robbed amount, irrespective of sets of houses robbed.


For example:
(i) Given the input array arr[] = {2, 3, 2} the output will be 3 because Mr X cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses. So, he’ll rob only house 2 (money = 3)

(ii) Given the input array arr[] = {1, 2, 3, 1} the output will be 4 because Mr X rob house 1 (money = 1) and then rob house 3 (money = 3).

(iii) Given the input array arr[] = {0} the output will be 0 because Mr. X has got nothing to rob.
Problem approach

This question is similar to House Robber-1 , the only difference being if we loot the first house then we cannot loot the last house and vice-versa . 

Approach for House Robber-2: 
Given an array nums and n=nums.size()
1) Initialise two vectors nums1 and nums2 , where nums1 contains all the elements of nums from index 0 to index n-2 and nums2 contains all the elements of nums from index 1 to index n-1.
2)Now , find the answer for nums1 and nums2 in the same way as House Robber-1.
3)Final Answer will be max(ans1,ans2) where ans1=answer for nums1 and ans2=answer for nums2


If you have not done House Robber-1 , here is a short approach on how to find the ans1 and ans2 .

Approach for House Robber-1
Given an array nums and n=nums.size()

1)Create a recursive function (int maxLoot(vector&nums , int idx) ) which returns the max answer that we can get for the array nums if we start traversing from index idx.

2)Now , for every element we have two options :

option1 = take that element and call maxLoot func for the rest of the array = nums[idx]+maxLoot(nums,idx+1)

option2=do not take that element at all = maxLoot(nums,idx+1)

3)Finally return max(option1 , option2)

4)Base Case : If idx>=n , simply return 0 as we cannot loot anymore houses.

5)Do not forget to memoise using a 1-D dp array
dp[idx]=max(op1,op2)

Try solving now

2. Nth Fibonacci Number

Easy
0/40
Asked in companies
SAP LabsHCL TechnologiesWalmart

The n-th term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula -

    F(n) = F(n - 1) + F(n - 2), 
    Where, F(1) = 1, F(2) = 1


Provided 'n' you have to find out the n-th Fibonacci Number. Handle edges cases like when 'n' = 1 or 'n' = 2 by using conditionals like if else and return what's expected.

"Indexing is start from 1"


Example :
Input: 6

Output: 8

Explanation: The number is ‘6’ so we have to find the “6th” Fibonacci number.
So by using the given formula of the Fibonacci series, we get the series:    
[ 1, 1, 2, 3, 5, 8, 13, 21]
So the “6th” element is “8” hence we get the output.
Problem approach

This problem is a simple recursive problem. But time complexity of simple recursive calls is exponential. In O(log(n)) this problem can be solved using a simple trick.

If n is even then k = n/2:
F(n) = [2*F(k-1) + F(k)]*F(k)

If n is odd then k = (n + 1)/2
F(n) = F(k)*F(k) + F(k-1)*F(k-1)

This method will solve this question in O(log(n)).

Try solving now
02
Round
Medium
Face to Face
Duration50 Minutes
Interview date22 May 2015
Coding problem2

Standard Data Structures and Algorithms round where I was given 2 questions to solve , one was from Linked List and the other was related to Priority Queue / Quick Sort .

1. Intersection of Linked Lists

Easy
20m average time
70% success
0/40
Asked in companies
IntuitAmazonWalmart

You are given two linked lists L1 and L2 which are sorted in ascending order. You have to make a linked list with the elements which are present in both the linked lists and are present in ascending order.

Example:-
L1 = 1->2->3->4->7
L2 = 2->4->6->7

ANSWER:- The answer should be 2->4->7 because 2,4, and 7 are present in both the linked lists.
Problem approach

Using Hashing : 

Basically, we need to find a common node of two linked lists. So we hash all nodes of the first list and then check the second list. 

Note : Hash the nodes not the node value
1) Create an empty hash set. 
2) Traverse the first linked list and insert all nodes' addresses in the hash set. 
3) Traverse the second list. For every node check if it is present in the hash set. If we find a node in the hash set, return the node

TC : O(m+n)
SC : O(min(m,n))


Using Two pointers : 

1) Initialize two pointers ptr1 and ptr2 at the head1 and head2.
2) Traverse through the lists,one node at a time.
3) When ptr1 reaches the end of a list, then redirect it to the head2.
4) Similarly when ptr2 reaches the end of a list, redirect it the head1.
5) Once both of them go through reassigning, they will be equidistant from the collision point
6) If at any node ptr1 meets ptr2, then it is the intersection node.
7) After second iteration if there is no intersection node it returns NULL.

TC : O(m+n) where m=Length of LL-1 and n=Length of LL-2
SC : O(1)

Try solving now

2. Kth largest element

Moderate
0/80
Asked in companies
MakeMyTripOracleWalmart

Ninja loves playing with numbers. One day Alice gives him some numbers and asks him to find the Kth largest value among them.

Problem approach

Naive Solution:

Keep an array of size k. The idea is to keep the array sorted increasing order so that the k'th largest element can be found in O(1) time.
How to process a new element of stream?
For every new element in stream, check if the new element is smaller than current k'th largest element. If yes, then ignore it. If no, then remove the smallest element from array and insert new element in sorted order. Time complexity of processing a new element becomes O(k).

Efficient Solution:

Use Min Heap of size k to store k largest elements of stream. Thr k'th largest element is always at root and can be found in O(1) time.
How to process a new element of stream?
Compare the new element with root of heap. If new element is smaller, then ignore it. Otherwise replace root with new element and call heapify for the root of modified heap.

Try solving now
03
Round
Easy
Face to Face
Duration50 Minutes
Interview date22 May 2015
Coding problem2

This round majorly focused on Real life appications of Data Structures and also revolved around Object Oriented Programming Style of writing code .

1. Data Structure Supporting Insert Delete And GetRandom

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

Design and implement a data structure which supports the following operations:

insert(X): Inserts an element X in the data structure and returns true if the element was not present, and false otherwise.

remove(X): Removes the element X from the data structure, if present. Returns true if the element was present and false otherwise.

search(X): Search the element X in the data structure. Returns true if the element was present and false otherwise.

getRandom(): Return a random element present in the data structure.

Four types of queries denote these operations:

Type 1: for insert(X) operation.
Type 2: for remove(X) operation.
Type 3: for search(X) operation.
Type 4: for getRandom() operation.
Note:
It is guaranteed that at least one element will be present in the data structure when getRandom() operation is performed.
Follow Up:
Can you implement every operation such that it works in O(1) time?
Problem approach

One way to solve it is to use two basic data structures:

-A resizable O(1) container elements (std::vector in C++, ArrayList in Java)
-A hash table elemToIndex which maintains mapping from an element to index.

Inserting an element val to the data structure involves two operations:
-elements.add(val)
-elemToIndex.put(val, elements.size() - 1)

GetRandom is just randomly choosing an index from 0 to elements.size() - 1.

Searching an element is easy, just find the element from the hash table.

Now the tricky part, remove. In an ideal case removing an element from an array is O(n). 
But here since we do not care about ordering, we can simply swap the element we want to delete with the last element, and pop off the last. Then update the map as well and we are done. This takes O(1) time and hence we achieved our target.

Try solving now

2. LRU Cache Implementation

Moderate
25m average time
65% success
0/80
Asked in companies
MicrosoftUberSalesforce

Design and implement a data structure for Least Recently Used (LRU) cache to support the following operations:

1. get(key) - Return the value of the key if the key exists in the cache, otherwise return -1.

2. put(key, value), Insert the value in the cache if the key is not already present or update the value of the given key if the key is already present. When the cache reaches its capacity, it should invalidate the least recently used item before inserting the new item.
You will be given ‘Q’ queries. Each query will belong to one of these two types:
Type 0: for get(key) operation.
Type 1: for put(key, value) operation.
Note :
1. The cache is initialized with a capacity (the maximum number of unique keys it can hold at a time).

2. Access to an item or key is defined as a get or a put operation on the key. The least recently used key is the one with the oldest access time.
Problem approach

Structure of an LRU Cache :

1) In practice, LRU cache is a kind of Queue — if an element is reaccessed, it goes to the end of the eviction order
2) This queue will have a specific capacity as the cache has a limited size. Whenever a new element is brought in, it is added at the head of the queue. When eviction happens, it happens from the tail of the queue.
3) Hitting data in the cache must be done in constant time, which isn't possible in Queue! But, it is possible with HashMap data structure
4) Removal of the least recently used element must be done in constant time, which means for the implementation of Queue, we'll use DoublyLinkedList instead of SingleLinkedList or an array.

LRU Algorithm :

The LRU algorithm is pretty easy! If the key is present in HashMap, it's a cache hit; else, it's a cache miss.

We'll follow two steps after a cache miss occurs:

1) Add a new element in front of the list.
2) Add a new entry in HashMap and refer to the head of the list.

And, we'll do two steps after a cache hit:

1) Remove the hit element and add it in front of the list.
2) Update HashMap with a new reference to the front of the list.

Tip : This is a very frequently asked question in interview and its implementation also gets quite cumbersome if you are doing it for the first time so better knock this question off before your SDE-interviews.

Try solving now
04
Round
Medium
Face to Face
Duration45 Minutes
Interview date22 May 2015
Coding problem2

This round was inclined towards some Low Level Design Principles and some concepts from Java .

1. System Design Question

Design a Railway Reservation System

Problem approach

Tip 1: Firstly, remember that the system design round is extremely open-ended and there’s no such thing as a standard answer. Even for the same question, you’ll have a totally different discussion with different interviewers. 

Tip 2:Before you jump into the solution always clarify all the assumptions you’re making at the beginning of the interview. Ask questions to identify the scope of the system. This will clear the initial doubt, and you will get to know what are the specific detail interviewer wants to consider in this service. 

Some standard steps that are being followed with respect to this question are : 

1) The first step is to provide the total number of passengers and submit all the necessary details of the passengers.
2) The next step is to enter the source and destination.
3) A list of available trains will appear. Among them, the user has to choose one.
4) The ticket value will be evaluated. The system will ask to enter the seat choice by showing the seat matrix. At last, a receipt will be generated on the screen.

Design your structure and functions according to the requirements and try to convey your thoughts properly to the interviewer so that you do not mess up while implementing the idea .


Finally , for acing System Design Rounds I would suggest watching Gaurav Sen's System Design Videos on YouTube and for hands on practice there is a Guided Path solely for System Design on CodeStudio which is very useful while preparing for these type of rounds.

2. OS Question

Why Java is platform independent and JVM platform dependent?

Problem approach

JVM is platform dependent because it takes java byte code and generates byte code for the current operating system. So Java software is platform dependent but Java language is platform independent because different operating system have different JVMs.

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
5 rounds | 6 problems
Interviewed by Walmart
4668 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 10 problems
Interviewed by Walmart
4972 views
0 comments
0 upvotes
company logo
SDE - 1
5 rounds | 8 problems
Interviewed by Walmart
915 views
0 comments
0 upvotes
company logo
SDE - 1
5 rounds | 8 problems
Interviewed by Walmart
1362 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