File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 358
358
1812|[ Determine Color of a Chessboard Square] ( ./1812-determine-color-of-a-chessboard-square.js ) |Easy|
359
359
1817|[ Finding the Users Active Minutes] ( ./1817-finding-the-users-active-minutes.js ) |Medium|
360
360
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|
361
362
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
362
363
1886|[ Determine Whether Matrix Can Be Obtained By Rotation] ( ./1886-determine-whether-matrix-can-be-obtained-by-rotation.js ) |Easy|
363
364
1920|[ Build Array from Permutation] ( ./1920-build-array-from-permutation.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments