PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Solve a two-jug measuring problem

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithm design, state-space modeling, graph-search techniques (BFS/DFS) and number-theoretic reasoning (gcd), along with handling edge cases and analyzing time and space complexity in the Coding & Algorithms domain.

  • Medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Solve a two-jug measuring problem

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

You are given two jugs with capacities x and y liters and an unlimited water source. You may perform these operations: fill a jug, empty a jug, or pour from one jug to the other until one becomes full or the other becomes empty. Determine whether it is possible to measure exactly z liters in either jug. If it is possible, return true and optionally output one valid sequence of operations; otherwise return false. Describe and analyze both a graph-search approach (e.g., BFS/DFS over states) and a number-theoretic approach (using properties of gcd), including edge cases such as z == 0, z > x + y, and when x or y is 0. Implement canMeasure(x, y, z) and provide time and space complexity.

Quick Answer: This question evaluates algorithm design, state-space modeling, graph-search techniques (BFS/DFS) and number-theoretic reasoning (gcd), along with handling edge cases and analyzing time and space complexity in the Coding & Algorithms domain.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given two jugs with capacities x and y liters and an unlimited water source. You may perform these operations: fill a jug, empty a jug, or pour from one jug to the other until one becomes full or the other becomes empty. Determine whether it is possible to measure exactly z liters in either jug. If it is possible, return true and optionally output one valid sequence of operations; otherwise return false. Describe and analyze both a graph-search approach (e.g., BFS/DFS over states) and a number-theoretic approach (using properties of gcd), including edge cases such as z == 0, z > x + y, and when x or y is 0. Implement canMeasure(x, y, z) and provide time and space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.