Ctrl K

Notebooks and Markers

Medium
Before the school year you have budget to spend. A notebook costs notebook_price and a marker costs marker_price. You may buy any number of notebooks and markers, including none, as long as the total does not exceed the budget; you do not have to spend all of it. A purchase is described by two numbers: how many notebooks and how many markers you take. Return the number of different purchases you can afford.
Example 1
budget=12, notebook_price=5, marker_price=3 → 9

With no notebooks you can take 0 to 4 markers: 5 options. With one notebook 7 is left, enough for 0 to 2 markers: 3 options. With two notebooks 2 is left, so no markers. In total 5 + 3 + 1 = 9.

Example 2
budget=3, notebook_price=4, marker_price=7 → 1

Nothing is affordable, so the only option is to buy nothing.

Constraints
  • 1 ≤ budget, notebook_price, marker_price ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumShuffle the Digits Into a Power of Two MediumSums of Two Powers MediumA Multiple Spelled With Two Digits MediumMicrowave Keypad Effort Medium
loading Python…
Input
budget=12, notebook_price=5, marker_price=3
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.