## Walmart Labs Interview Questions

- 0of 0 votes
How to design a system which allows millions of requests

- 0of 0 votes
Design an app which allows different types of jobs to be triggered at user specified delay

- 0of 0 votes
Given a dictionary containing some words, and a start word and end word, you need to find the minimum number of conversion needed to convert start word to end word with the following restrictions :-

1. Each intermediate word must be in the dictionary

2. You can change only one character in the word to convert to another word.

Example If You are given start word as ‘SAT’ and end word as ‘PAN

and the dictionary contains words = [‘RAT’,’PAT’,’DAM’]

then SAT -> PAT ->PAN is the answer.

- 0of 0 votes
How to find total number of greater number after all number in an array ?

Eg. Given array is,

5 3 9 8 2 6

o/p

3 3 0 0 1 0

- 1of 1 vote
Two friends Kohli and Dhoni want to test their friendship to check how compatible they are. Given a list of n movies numbered 1,2,3....n and asked both of them to rank the movies.

Design an algorithm to find compatibility difference between them.

Compatibility difference is the number of mis-matches in the relative rankings of the same movie given by them i.e. if Kohli ranks Movie 3 before Movie 2 and Dhoni ranks Movie 2 before Movie 3 then its a relative ranking mis-match Compatibility difference is the maximum number of mis-matches

Sample Input

5

31245

32415

Sample Output

2

Explanation

Movies are 1,2,3,4,5. Kohli ranks them 3,1,2,4,5, Dhoni ranks them 3,2,4,1,5. Compatibility difference is 2 because Kohli ranks movie 1 before 2,4 but Dhoni ranks it after.

- 0of 0 votes
Mario wants to reach to his princess who is waiting for him in a castle. But the way to the castle is full of dragons. Each dragon is an enemy of the dragon who is located just before him on that path. The dragons in this world are quite peculiar. They have some number of diamonds each. Although they are dragons, they won't burn, instead they will give Mario their diamonds, but if and only if, Mario didn't take any diamonds from the dragon standing directly before the current one. If Mario does, then that dragon will burn him. Mario is in your control. You have to make Mario collect maximum number of diamonds for his princess and reach castle safely.

Input- Each test case starts with a number N, the number of dragons, 0 <= N <= 10^4. The next line will have N numbers, number of diamonds each dragon has, 0 <= The number of diamonds with each dragon <= 10^9. Dragons described in the order they are encountered on the way to the castle.

Output- Print the maximum number of diamonds you can collect (and reach to castle safely).

Sample Input

5 1 2 3 4 5

Sample Output

9

Explanation

Input - 5 ==> Represents number of Dragons 1 2 3 4 5 ==> Represents the diamonds each of the Dragon has consecutively. The first dragon has 1 , the second has 2 and so on....

Output- 9

Explanation- If Mario collects diamonds from 1st, 3rd and 5th dragon (1+3+5). He will get 9 diamonds which is the maximum number of diamonds he can collect. Two of the other possible ways in which he can collect diamonds is, from 2nd and 4th dragon, (2+4),i.e.(6) or from 2nd and 5th dragon (2+5) i.e.,7 . He can’t obtain more than 9 diamonds in any case.

Therefore the output would be 9, the maximum he can collect.

- 0of 0 votes
Find the number of column-swaps required to find the largest rectangle of all ones in a matrix.

The question is similar to the one in this link-

http://www.geeksforgeeks.org/find-the-largest-rectangle-of-1s-with-swapping-of-columns-allowed/

But we need to find the number of minimum swaps required

- 0of 0 votes
Find the value of (x, y) in Pascal's triangle. I wrote code to construct the Pascal's triangle upto the required (x, y). Then interviewer asked me to change code so that I dont have to calculate the whole triangle but only the necessary parts.

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

For example, in order to calculate f(4, 1) which is 4, we only need to calculate f(3, 0) and f(3, 1). And for f(3, 1) we need to calculate f(2, 0) and f(2, 1) and so on. After getting the hint, I wrote the recursive code and then he asked my for complexity of the code.`int pascals(int x, int y){ if(x == 0 or x == y) return 1; return(pascals(x - 1, y) + pascals (x- 1, y - 1); }`

- 0of 0 votes
Implement pow(x, y) which should return x^y. Both iterative and recursive.

- 0of 0 votes
Print all permutations of a string and give the complexity of the algorithm.

- 0of 0 votes
Given a tree (incolmplete and/or unbalanced), how would you write it to disk so it can be moved to another machine and recreated?

- 0of 0 votes
There is a garden of strawberry plants represented by a 2D, square array.Each plant represents an element in the matrix ie it has a number of strawberries. If a plant doesnt have strawberries it is denoted by 0. If 0 is encountered you cannot travel through that path.

You can start from any cell along the left border of this ground (i.e the matrix) and travel until it finally stops at one cell in the right border, and you can only move to up/down/right. You can only visit each cell once. Calculate the maximum number of berries is obtained.

Backtracking using Dynamic programming is one of the methods i have thought of.

Also there some special conditions:

a.Even in the left border and right border, we can go up and down.

b. When we are at the top cell of one column, we can still go up, which demands us to

pay all current strawberries , then we will be teleported to the bottom cell of this column and vice

versa.

Input: user enters dimensions of ground ie size of matrix and the matrix itself

Output: is the maximum number of strawberries collected without encountering 0; in case we do we display 0.

Till now i have managed to find the largest value in the first column of the matrix but i am facing difficulty in testing the neighbours of that cell.

Also i am not able to store the position of the cell which i started from or even mark it.

Input

4 4

-1 4 5 1

2 -1 2 4

3 3 -1 3

4 2 1 2

output

23

Input

4 4

-1 4 5 1

2 -1 2 4

3 3 -1 -1

4 2 1 2

output

22

- 1of 1 vote
. Given n strings consisting of ‘R’ and ‘B’. Two strings can be only combined if last character of first string and first character of second string are same. Given n strings, you have to output the maximum length possible by combining strings.

I/P

RBR

BBR

RRR

output : 9

- 0of 0 votes
Implemented a bounded queue:

Read:

If queue is empty, wait till it can return a value with time out

If another thread is reading from the queue then wait till that thread is done

Remove the first element from the queue and return it

Do not block if a thread is writing into the queue

Write:

If queue is full, wait till one value is read with time out

If another thread is writing to the queue, wait till that thread is done

Write the element at the end of the queue

Do not block if a thread is reading from the queue

- 1of 1 vote
Given a start string, end string and a set of strings, find if there exists a path between the start string and end string via the set of strings.

A path exists if we can get from start string to end string by changing (no addition/removal) only one character at a time. The restriction is that the new string generated after changing one character has to be in the set.

start: "cog"

end: "bad"

set: ["bag", "cag", "cat", "fag", "con", "rat", "sat", "fog"]

one of the paths: "cog" -> "fog" -> "fag" -> "bag" -> "bad"

- 0of 0 votes
Given an array of integers (+ve & -ve) find two equal sized contiguous non-overlapping sub-arrays with maximum dot-product

- 0of 0 votes
Write an OO class system for individual-contributors, managers, directors.

- 0of 0 votes
Minimize the cost to chop the log into pieces of desired lengths. The cost to cut any piece is the max of the two lengths generated out of cutting the wood. e.g. If a 14 unit log is cut into 2 pieces of lengths 6 and 8, cost is 8.

Write a function that takes the total length of the log and an array of piece lengths and returns the cheapest sequence to do this along with the cost

- 0of 0 votes
Given an existing inventory Oracle Database system and UI. The UI should update itself as soon as the db gets updated

There is a tool that people use to dump inventory data (one row at a time or bulk insert via data in files)

Currently a new system is built with new UI using No Sql database.

Write a bridge that will update the new UI and populate the No SQL database, so that the new UI has real time updates as the tool has updated.

- -1of 1 vote
`public class StringUtilities { /** * Count the maximum depth of parenthesis nesting, i.e. "abc(123(xyz))m(((n)))o" -> 3. * * @param input * any string * @return deepest parenthesization level * @throws IllegalArgumentException * if input is null or contains a mismatch "a)b(c" or "a(b" */ public static int nestedParenthesisDepth(String input) throws IllegalArgumentException { //... } }`

- -2of 4 votes
public class MyClass {

public static int num=1;

public static boolean flag=false;

public static void main(String[] args) {

Thread t =new Thread(new MyThread());

t.start();

MyClass.flag=true;

MyClass.num=10;

}

}

class MyThread implements Runnable{

public void run() {

while(!MyClass.flag){

Thread.yield();

}

System.out.println(MyClass.num);

}

}

Output of this code and the reason for the output?

- 0of 0 votes
Input any string, count the maximum depth of parenthesis nesting, i.e. "abc(123(xyz))m(((n)))o" -> 3.

if input is null or contains a mismatch "a)b(c" or "a(b"

Also some other samples:

(((()))) -> 4

()()()() -> 1

- 1of 1 vote
You have a class that many libraries depend on. You need to modify the class for one application. Which of the following changes require recompiling all libraries before it is safe to build the application?

a. add a constructor

b. add a data member

c. change destructor into virtual

d. add an argument with default value to an existing member function

- -1of 1 vote
Do thread join without join function?

- 0of 0 votes
Given a BST, how would you return the kth smallest element. Cover all the corner cases with time complexity logn

- 0of 0 votes
Write a program that reverses alternate elements in a given linked list input: a->b->c->d, output should be b->a->d->c

- 1of 1 vote
Asked at Walmart Labs

----------------------------------

There is a row of seats. Assume that it contains 15 seats adjacent to each other. There is a group of people who are already seating in that row randomly. i.e. some are sitting together & some are scattered.

Take the row as a String in java.

The seat which is occupied is marked with a character 'X' & which is not occupied is marked with a dot '.'

Now your target is to make the whole group sit together i.e. next to each other and without having any vacant seat between them in such a way that the total number of hops or jumps at the end of the grouping them together should be minimum.

Ok let me try to explain you in details.

Here is the row having 15 seats represented by the String (0, 1, 2, 3, ......... , 14) -

. . . . x . . x x . . . x . .

Now to make them sit together one of approaches is - . . . . . . x x x x . . . . .

Following are the steps to achieve this -

1 - Move the person sitting at 4th index to 6th index - Number of jumps by him = (6 - 4) = 2

2 - Bring the person sitting at 12th index to 9th index - Number of jumps by him = (12 - 9) = 3

------------------------------------------------------------------------------------------------------------------------------------------------------------

So now the total number of jumps made = ( 2 + 3) = 5 which is the minimum possible jumps to make them seat together.

There are also other ways to make them sit together but the number of jumps will exceed 5 & that will not be minimum.

For example bring them all towards the starting of the row i.e. start placing them from index 0. In that case the total number of jumps will be ( 4 + 6 + 6 + 9 ) = 25 which is very costly and not an optimized way to do this movement.

Now write an algorithm which will return the minimum number of jumps required to make them sit together.

- 0of 0 votes
There is a matrix of very large dimension (10^30 * 10*40) of characters. You need to search a string of length 10^10 inside the matrix. Adjacent characters in any direction can be chosen and same cell can be counted multiple times to find the pattern

- 0of 0 votes
You need to select an ad among large no. of advertisements depending on n keywords. What data structure should be used to serve the request efficiently

- 2of 2 votes
Design a stack in such a way that the operations Push, Pop and Find Minimum can be done in O(1). Assume space as not a constraint.