Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Introduction to Simulation Pattern
You have 9 full water bottles. The shop trades 3 empty bottles for 1 full one. How many bottles can you drink in total?
drink 9 empties 9 trade 9 empties for 3 full
drink 3 empties 3 trade 3 empties for 1 full
drink 1 empties 1 1 is fewer than 3, so stop
total drunk = 13
There is a formula for this one. Finding it takes longer than the interview allows, and getting it slightly wrong gives an answer that looks right.
The rules were already written down in the question. Follow them
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%