Walmart Labs Interview Question for Software Developers


Team: Customer experience
Country: United States
Interview Type: In-Person




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

Give a piece of wood:
_____|______|_____

We want to find the least, and cheapest, way to cut it.
We also want to get the largest free cut as possible(if 1 cut gives two pieces).

Let's say we have 21 and we want to cut (7,7,6).
7+7+6 = 20 < 21

21 0
subtract 7 and add to right side
14 7
subtract 7 add to right size
7 14
subtract 6 add to right side
1 19
Now pick the one that minimizes |l - r|
which is 7 14
We already got 7 for "free" 
Cost 14
Then recurse on the smallest side that you can take the largest cut of using the same technique:
14 0
7 7
0 14
|l-r| = 7 7
7 0
0 7
etc.
Cost = 27

Let's say we cut (9, 8, 3, 1)
21 0
12 9
4 17
1 20
0 21
Take the one that minimizes |l - r| = 12 9
We get 9 for "free" 
Cost 12
12 0
4 8
1 11
|4 8|
etc.
Total cost 12 + 8 + 3 

(6,6,6)
21 0
15 6
9 12
3 18
Take that one that minimized |l-r| = 9 12
Cost 12
9 0
3 6
0 9
|l-r| = 3 6
12 0
6 6
0 12
|l-r| = 6 6
Cost = 12 + 6 + 6

(1, 1, 1)
21 0
20 1
19 2
18 3
Minimize |l-r| = 18 3
cost 18 + 2 + 1

I believe this should work. The main idea is we want to make our first cut as close to n/2 as possible without making it impossible to to get the correct lengths down the line. By finding the cuts in this way, we are guaranteed that, by continuing to cut, we can get the corrects lengths afterwards.

Should work better than my previous attempt. Once again, if someone sees a problem. I would like to know.

- SycophantEve June 24, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awesome man..u nailed it

- Raghu August 27, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if you need to cut in (7, 7, 6) pieces.

- Anonymous June 24, 2015 | 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