Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c3dcca6

Browse files
committedJan 10, 2025
Add solution #1833
1 parent 8388461 commit c3dcca6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
1812|[Determine Color of a Chessboard Square](./1812-determine-color-of-a-chessboard-square.js)|Easy|
359359
1817|[Finding the Users Active Minutes](./1817-finding-the-users-active-minutes.js)|Medium|
360360
1832|[Check if the Sentence Is Pangram](./1832-check-if-the-sentence-is-pangram.js)|Easy|
361+
1833|[Maximum Ice Cream Bars](./1833-maximum-ice-cream-bars.js)|Medium|
361362
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
362363
1886|[Determine Whether Matrix Can Be Obtained By Rotation](./1886-determine-whether-matrix-can-be-obtained-by-rotation.js)|Easy|
363364
1920|[Build Array from Permutation](./1920-build-array-from-permutation.js)|Easy|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 1833. Maximum Ice Cream Bars
3+
* https://leetcode.com/problems/maximum-ice-cream-bars/
4+
* Difficulty: Medium
5+
*
6+
* It is a sweltering summer day, and a boy wants to buy some ice cream bars.
7+
*
8+
* At the store, there are n ice cream bars. You are given an array costs of
9+
* length n, where costs[i] is the price of the ith ice cream bar in coins.
10+
* The boy initially has coins coins to spend, and he wants to buy as many
11+
* ice cream bars as possible.
12+
*
13+
* Note: The boy can buy the ice cream bars in any order.
14+
*
15+
* Return the maximum number of ice cream bars the boy can buy with coins.
16+
*/
17+
18+
/**
19+
* @param {number[]} costs
20+
* @param {number} coins
21+
* @return {number}
22+
*/
23+
var maxIceCream = function(costs, coins) {
24+
let count = 0;
25+
costs.sort((a, b) => a - b);
26+
for (let i = 0; i < costs.length; i++) {
27+
if (costs[i] <= coins) {
28+
count++;
29+
coins -= costs[i];
30+
}
31+
}
32+
return count;
33+
};

0 commit comments

Comments
 (0)
Please sign in to comment.