Leetcode 2240. Number of Ways to Buy Pens and Pencils
Count the number of nonnegative integer pairs (pens, pencils) satisfying cost1*pens + cost2*pencils ≤ total — i.e., count integer solutions to a linear inequality. This is solved by iterating one item count up to total/cost and summing how many of the other fit (O(total/min(cost))).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.