I recently had an interview with Walmart for the Software Development Engineer (SDE-1) position. The interview process consisted of two rounds, and I had a week's gap between them. The interviewers were friendly, knowledgeable, and supportive throughout the process. However, I was not accepted after the second round.
In the first round, the interviewer started with a brief introduction and then asked me two coding questions. The first question was to find all possible combinations of a given string, and the second question was to find the first failed build in an array of builds. The builds on the left side are passed builds, and the builds on the right side are failed builds.
For the first question, I used recursion to find all possible combinations of the given string. Here's the Java code for it:
public static void combinations(String s, String prefix) {
if (s.length() == 0) {
System.out.println(prefix);
} else {
for (int i = 0; i < s.length(); i++) {
combinations(s.substring(i + 1), prefix + s.charAt(i));
}
}
}
For the second question, I used a binary search algorithm to find the first failed build. Here's the Java code for it:
public static int findFailedBuild(int[] builds) {
int start = 0;
int end = builds.length - 1;
int mid;
while (start <= end) {
mid = start + (end - start) / 2;
if (isBuildSucessfull(builds[mid])) {
start = mid + 1;
} else {
end = mid - 1;
}
}
return end + 1;
}
public static boolean isBuildSucessfull(int build) {
// implementation for checking if build is successful or not
}
In the second round of the interview for the SDE-1 position at Walmart, I was asked two coding questions related to arrays.
The first question was to find the start point and maximum number of shampoos for each club member, given a 2D array representing the club and their shampoo inventory. Each row in the array represented a member, and each column represented the number of shampoos they had at a particular position. For example, the 2D array club = [[1,0,1],[0,0,1],[0,1,1]]
represented a club with three members, and their shampoo inventory was as follows:
Member_1 => 1, 0, 1
Member_2 => 0, 0, 1
Member_3 => 0, 1, 1
The output was expected to be a 2D array containing the start point and maximum number of shampoos for each member, sorted in descending order of the start points. For example, the output for the above input should be [[0,2],[0,0]]
, where the first member had a start point of [0,2]
with a maximum number of shampoos of 4
, and the second member had a start point of [0,0]
with a maximum number of shampoos of 1
.
To solve this problem, I used a brute force approach that involved iterating through each element in the array and calculating the maximum number of shampoos for each member. However, this approach had a time complexity of O(n^3), which was not efficient. The interviewer then provided a hint to use dynamic programming to optimize the solution.
With the help of the hint, I came up with an optimized solution that involved creating two arrays to store the maximum number of shampoos and start points for each member. I used a prefix sum approach to calculate the maximum number of shampoos and a two-pointer approach to calculate the start point. The time complexity of the optimized solution was O(n^2), which was much better than the brute force approach.
The second question was to write a program to find the product of all the elements in an array except the current element without using the division operation. The input was an integer array nums
, and the output was an array answer
such that answer[i]
was equal to the product of all the elements in nums
except nums[i]
. The product of any prefix or suffix of nums
was guaranteed to fit in a 32-bit integer.
To solve this problem, I used a prefix and suffix product approach. I created two arrays prefix
and suffix
to store the product of all the elements before and after the current element, respectively. I then calculated the product of all the elements except the current element by multiplying the values in the prefix
and suffix
arrays at the corresponding indices. The time complexity of the solution was O(n), which met the requirement of the problem.
In addition to the coding questions, the interviewer also asked some basic questions about Java and my experience with it. Overall, the second round of the interview was challenging yet rewarding, and I felt confident about my solutions to the coding questions.
After the interview process, I waited for a few days to hear back from the company. Unfortunately, I received an email stating that I was not selected for the position. It was disheartening to receive the news, but I took it as a learning experience and an opportunity to improve myself for future interviews.
In conclusion, my interview experience with Walmart was challenging yet rewarding. The questions asked in the interview tested my coding skills, problem-solving ability, and knowledge of programming concepts. I prepared well for the interview and gave my best effort in each round. Although I was not selected for the position, I gained valuable experience and feedback that will help me in my future endeavors.