Skip to content

Instantly share code, notes, and snippets.

@Maslor
Created August 10, 2015 15:11
Show Gist options
  • Save Maslor/6e8a67a9ff78fb376742 to your computer and use it in GitHub Desktop.
Save Maslor/6e8a67a9ff78fb376742 to your computer and use it in GitHub Desktop.
Receives an array of customer bills and returns YES or NO depending on whether you can or can't give them all change, assuming you start with 0$. Ticket value is 25 and customers only carry 3 kinds of bills: 25$, 50$ and 100$
public class TicketLine {
public static String Tickets(int[] peopleInLine) {
int money=0;
for(int i = 0;i<peopleInLine.length;i++){
if(peopleInLine[i] == 50){
if (money < 25) return "NO";
else money+=25;
}
else if (peopleInLine[i] == 100) {
if(money < 75) return "NO";
else money+=25;
}
else money+=25;
}
return "YES";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment