Practice Number of Ways to Buy Pens and Pencils
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil. Return the number of distinct ways you can buy some number of pens and pencils.
Source: Number of Ways to Buy Pens and Pencils on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
total = 20, cost1 = 10, cost2 = 5
9
# Example 2
total = 5, cost1 = 10, cost2 = 10
1
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Ways to Buy Pens and Pencils.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.