Skip to content

Instantly share code, notes, and snippets.

@langolf
Created July 17, 2025 16:19
Show Gist options
  • Save langolf/81a66ff21a19d4070df63d68afce4693 to your computer and use it in GitHub Desktop.
Save langolf/81a66ff21a19d4070df63d68afce4693 to your computer and use it in GitHub Desktop.
/**
* @param {number[]} bills
* @return {boolean}
*/
var lemonadeChange = function (bills) {
let tens = 0;
let fiths = 0;
while (bills.length) {
const client = bills.shift();
if (client === 5) {
fiths += 5;
}
if (client === 10) {
if (fiths > 0) {
fiths -= 5;
tens += 10;
} else {
return false;
}
}
if (client === 20) {
if (tens > 0 && fiths > 0) {
tens -= 10;
fiths -= 5;
} else if (tens === 0 && fiths > 10) {
fiths -= 15;
} else {
return false;
}
}
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment