Created
August 10, 2015 15:11
-
-
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$
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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