Using JavaScript:
const changes = { 25: 0, 50: 0 }; const procedure = cash => { switch (cash) { case 25: changes[25]++; return true; case 50: if (changes[25] > 0) { changes[50]++; changes[25]--; return true; } else { return false; } case 100: if (changes[50] > 0 && changes[25] > 0) { changes[50]--; changes[25]--; return true; } else if (changes[25] > 2) { changes[25] -= 3; return true; } else { return false; } } }; const tickets = queue => queue.every(procedure) ? 'YES' : 'NO'; console.log(tickets([25, 25, 50, 50, 100])); // NO console.log(tickets([25, 25, 50, 50])); // YES console.log(tickets([25, 50, 25, 100])); // YES
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Using JavaScript: