func maximumToys(prices: [Int], k: Int) -> Int {
var ans = 0
let sortedPrices = prices.sorted()
var budget = k
for p in sortedPrices {
if budget > p {
budget -= p
ans += 1
}
}
return ans
}
'Computer Science > Algorithm with Code' 카테고리의 다른 글
[HackerRank] Preparation_Kit (11. Two Strings) [Dictionaries & Hashmaps] (0) | 2024.09.27 |
---|---|
[HackerRank] Preparation_Kit (10. Ransom Note) [Dictionaries & Hashmaps] (2) | 2024.09.27 |
[HackerRank] Preparation_Kit (08. Minimum Swaps 2) [Array] (1) | 2024.09.26 |
[HackerRank] Preparation_Kit (06. Left Rotation) [Array] (0) | 2024.09.21 |
[HackerRank] Preparation_Kit (05. 2D Array - DS) [Array] (0) | 2024.09.19 |