|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-ice-cream-bars/">1833. Maximum Ice Cream Bars</a></h2><h3>Medium</h3><hr><div><p>It is a sweltering summer day, and a boy wants to buy some ice cream bars.</p> |
| 2 | + |
| 3 | +<p>At the store, there are <code>n</code> ice cream bars. You are given an array <code>costs</code> of length <code>n</code>, where <code>costs[i]</code> is the price of the <code>i<sup>th</sup></code> ice cream bar in coins. The boy initially has <code>coins</code> coins to spend, and he wants to buy as many ice cream bars as possible. </p> |
| 4 | + |
| 5 | +<p>Return <em>the <strong>maximum</strong> number of ice cream bars the boy can buy with </em><code>coins</code><em> coins.</em></p> |
| 6 | + |
| 7 | +<p><strong>Note:</strong> The boy can buy the ice cream bars in any order.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre style="position: relative;"><strong>Input:</strong> costs = [1,3,2,4,1], coins = 7 |
| 13 | +<strong>Output:</strong> 4 |
| 14 | +<strong>Explanation: </strong>The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7. |
| 15 | +<div class="open_grepper_editor" title="Edit & Save To Grepper"></div></pre> |
| 16 | + |
| 17 | +<p><strong class="example">Example 2:</strong></p> |
| 18 | + |
| 19 | +<pre style="position: relative;"><strong>Input:</strong> costs = [10,6,8,7,7,8], coins = 5 |
| 20 | +<strong>Output:</strong> 0 |
| 21 | +<strong>Explanation: </strong>The boy cannot afford any of the ice cream bars. |
| 22 | +<div class="open_grepper_editor" title="Edit & Save To Grepper"></div></pre> |
| 23 | + |
| 24 | +<p><strong class="example">Example 3:</strong></p> |
| 25 | + |
| 26 | +<pre style="position: relative;"><strong>Input:</strong> costs = [1,6,3,1,2,5], coins = 20 |
| 27 | +<strong>Output:</strong> 6 |
| 28 | +<strong>Explanation: </strong>The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18. |
| 29 | +<div class="open_grepper_editor" title="Edit & Save To Grepper"></div></pre> |
| 30 | + |
| 31 | +<p> </p> |
| 32 | +<p><strong>Constraints:</strong></p> |
| 33 | + |
| 34 | +<ul> |
| 35 | + <li><code>costs.length == n</code></li> |
| 36 | + <li><code>1 <= n <= 10<sup>5</sup></code></li> |
| 37 | + <li><code>1 <= costs[i] <= 10<sup>5</sup></code></li> |
| 38 | + <li><code>1 <= coins <= 10<sup>8</sup></code></li> |
| 39 | +</ul></div> |
0 commit comments