Walmart Labs Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be turned into a graph problem. The fact that the graph and the query is huge should be of no concern at first; start simple.

We treat the matrix of characters as a graph such that there is an edge from a cell to all 8 adjacent cells (less for the cells along the edges). There's also an edge from a cell to itself.

The first thing to do would be to do an O(n) scan of the matrix to find all cells that begin with the same character as the query string.

Next, we can perform an A* search from each of those cells. Our heuristic is the # of characters not yet matched. We only generate children who satisfy the criteria that their cell contains the next character in the query. We can terminate the search if the open list is empty and we haven't found a solution, exactly like A*.

Because we're not guaranteed to find a string match in the matrix, our worst case will be something like O(V^2), where we've performed a BFS from each node in the graph.

- Stu November 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Wrong. A* is wrong solution and bad idea. Not bfs we should use depth.

- Anonymous November 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

What are you saying? 10^30*10*40 characters? Assume 1 byte for each character.
1GigaByte = 1024*1024*1024 bytes
10^32 bytes = 10^23 GigaBytes
You cannot have this much memory (or even secondary storage) available.

Now let us assume that somehow we manage to arrange this massive memory. You know that you have to visit each character at least once. To process 10^7 characters it takes an order of a second assuming O(1) for each character. Now to process 10^32 characters it will take 10^25 seconds means 10^17 years.

- EOF November 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Who are saying that EACH cell in this matrix is translated to memory or any storage? We can save only not-null values into memory and realise function which return value (or null) by index. For example, excel do not save empty cells in a memory. Moreover, this task is abstract and we must solve it without any connections to memory size and real times.

- roman.potapkin November 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@EOF.. Don't take things literally. The numbers are exaggerated to understand the thinking process when solving big problems. It would also help to bring in optimal solutions, when thinking of 3x3 arrays, 0(n^2) doesn't sound bad, but not when thinking of 10^30*10^40 arrays..

- Teja November 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

That is a very big machine. The earth has 10^50 atoms in it some out of the box thinking will be required. Did your interviewers had big almond shaped eyes, big heads and a gray pallor?
All joking aside we have a big matrix or the matrix is very sparse and or does not have to actually be stored like say the number of states in some game.
The simple algorithm is to do a recursive search starting at every node in the matrix. At each recursion try all 4 directions including the one we came from. We are talking perhaps 10 to 40 lines of code. if we have some way to quickly iterate through nodes of a particular value then this comes into the realm of reality. At 10^10 notes on where we have been we will probably go to an iterative solution that moves back and forth along a big file stored on some disks.
We can give each starting node to a different processor if we are talking a parallel computing and we could even fork off different branches of a search at any point along the way if we wanted. We might even consider starting in the middle of the string to be found and giving each side to a different processor. Under some regimes this might help though I can't be sure.

- Dr A' November 10, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More