Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 4, 2023
1 parent 42018f0 commit c7175eb
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Runtime: O(nlogn)
// Space: O(1)

function nonConstructibleChange(coins) {
coins.sort((a, b) => a - b);

let currentChangeCreated = 0;

for (let coin of coins) {
if (coin > currentChangeCreated + 1) {
return currentChangeCreated + 1;
}

currentChangeCreated += coin;
}

return currentChangeCreated + 1;
}

0 comments on commit c7175eb

Please sign in to comment.