Code Logo

Check Water Bottle Empty

Published at19 Apr 2026
Logic & Conditionals Easy 6 views
Like0

Given the current water level in milliliters and the bottle's total capacity, determine whether the bottle is empty. Return true if the water level is 0, false otherwise.

For example, if the water level is 0 ml, the bottle is empty — return true. If the level is 500 ml, the bottle is not empty — return false. The capacity is provided but is not needed to check emptiness — only the current level matters.

This problem teaches boolean logic and comparison operators. Checking whether a value equals zero is one of the simplest conditional checks. It is used in inventory systems (checking stock depletion), sensor monitoring (detecting empty tanks), and state management (checking if a queue is drained).

The solution compares the water level to 0 and returns the boolean result. If level equals 0, the bottle is empty. Otherwise, it has some water remaining.

Edge cases include a negative water level (should not occur but would technically not be empty), a level equal to exactly 0 (empty), and a level exceeding capacity (the bottle still has water, so not empty).

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
amount = 250
Output
HAS WATER
Explanation

There is still water left in the bottle.

Example 2
Input
amount = 1
Output
HAS WATER
Explanation

Any amount above zero means the bottle is not empty.

Example 3
Input
amount = 0
Output
EMPTY
Explanation

No water left means the bottle is empty.

Algorithm Flow

Recommendation Algorithm Flow for Check Water Bottle Empty
Recommendation Algorithm Flow for Check Water Bottle Empty

Solution Approach

Compare the water level to 0 and return whether they are equal as a boolean result.

function isEmpty(level, capacity)
  return level == 0

Return the result of the comparison level == 0. This expression produces true when the water level is exactly 0 and false when there is any water remaining. The capacity parameter is provided for context in real-world scenarios but is not required for the emptiness check — only the current level determines whether the bottle is empty.

This is the simplest possible boolean function: it performs a single comparison and returns the result directly. The equality operator (==) compares two values and produces a boolean outcome without needing any conditional branching in the code.

Time complexity is O(1), space complexity is O(1).

Best Answers

Pseudocode - Approach 1
program check_water_bottle_empty
dictionary
   amount: integer
algorithm
   input(amount)
   if amount = 0 then
      output("EMPTY")
   else
      output("HAS WATER")
   endif
endprogram