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.

- Mani May 14, 2018 | Flag Reply
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)]

- Mani May 14, 2018 | Flag Reply
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)

- Lukas May 18, 2018 | Flag Reply
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)

- Lukas May 18, 2018 | Flag Reply
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))
    }
  }

- emir10xrec May 31, 2018 | 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