Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Wall Building With Bricks

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Wall Building With Bricks. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Searce's deployment planning tools need to determine whether a wall segment can be assembled exactly from unlimited bricks of two available lengths. Given the wall length and two positive brick lengths, return whether some non-negative combination of the two brick lengths equals the wall length.

A valid construction must satisfy:

wall_length = x * brick_length_a + y * brick_length_b

where x and y are non-negative integers. Bricks may be reused any number of times, and unused space is not allowed.

Formal Specification

Implement can_build_wall(wall_length, brick_length_a, brick_length_b).

  • Input: three integers representing the required wall length and the two available brick lengths.
  • Output: a boolean. Return True if the wall can be constructed exactly, otherwise return False.

Constraints

  • 0 <= wall_length <= 10^12
  • 1 <= brick_length_a, brick_length_b <= 10^12
  • Brick quantities must be non-negative integers
  • The wall must be constructed exactly

Function Signature

def can_build_wall(wall_length, brick_length_a, brick_length_b):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output