## Interview Question for Software Engineers

Country: United States
Interview Type: In-Person

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

Just find there is a number that exists within the min_max range divisible by options and their combinations
In this example that would be (3,4,7,10,11)

You don't need to calculate for each value in min-max range of cup. just calculate for minimum value, if the remainder is any one of the options+combinations array, we should be returning a true.

The solution can be optimised further as it's an O(n*k) still.

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

In order to figure out if the coffee can be filed, one of the following should lie in the min-max range of cup
- Multiples of pouring options or their combinations (3/4/7/10/11)
[10 and 11 are 3+7 and 4+7 (3+4 is already covered)]

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

all values >= 20 can be hit:

``````X % 4 == 0 ? X/4 * 4
X % 4 == 3 ? (X div 4 - 1) * 4 + 1 * 7
X % 4 == 2 ? (X div 4 - 3) * 4 + 2 * 7
X % 4 == 1 ? (X div 4 - 5) * 4 + 3 * 7``````

for values <20 simply write a table in O(1)

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

all values >= 20 can be hit:

``````X % 4 == 0 ? X/4 * 4
X % 4 == 3 ? (X div 4 - 1) * 4 + 1 * 7
X % 4 == 2 ? (X div 4 - 3) * 4 + 2 * 7
X % 4 == 1 ? (X div 4 - 5) * 4 + 3 * 7``````

for values <20 simply write a table in O(1)

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

For small min and max values brute force recursive just works:

``````def canFillTheCup(min: Int, max: Int, buttonAmounts: Seq[Int]): Boolean = {
if (buttonAmounts.exists(ba => min <= ba && ba <= max)) {
true
} else {
buttonAmounts.exists(ba => min - ba > 0 && canFillTheCup(min - ba, max - ba, buttonAmounts))
}
}``````

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.

### 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.