Google Online Assessment (OA) - Water Plants

You work in a restaurant and is tasked to fill some bowls with soup in a big stock pot. The bowls are positioned in a row, and you are going to fill the bowls with a large ladle. To avoid mistakes, you have decided to:

  • Fill the bowls from left to right;
  • Fill each bowl if you have enough soup for it, otherwise refill the ladle with more soup;
  • Fill each bowl in one go without taking a break to refill the ladle. This means that you may sometimes have to refill your ladle before or after filling a bowl, even though the ladle isn't completely empty.

You start at the stock pot, which is positioned one step before the first bowl. How many steps will you take to finish filling all the bowls in the row? The bowls are positioned one step apart from each other.

Given an array of n integers representing the amount of soup required for each bowl and the ladle capacity, return the number of steps needed to fill all the bowls.


  • 1 <= n <= 1000
  • 1 <= bowls[i] <= 10^6
  • 1 <= capacity <= 10^9
  • The ladle is large enough to fully fill any bowl


Example 1:


bowls = [2, 4, 5, 1, 2]

capacity = 6

Output: 17

First, you fill bowl 0 and 1 - 2 steps. Then, you go back and refill - 2 steps - and fill bowl 2 and 3 - 4 steps. You go back and refill - 4 steps - and fill bowl 4 - 5 steps. So you take a total of 2 + 2 + 4 + 4 + 5 = 17 steps.

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]

Get premium for instant access to all content and solutions