Skip to content

Instantly share code, notes, and snippets.

@lokeshh
Created June 20, 2018 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokeshh/ae78fc9ddbf1f8c748f555122d832bc7 to your computer and use it in GitHub Desktop.
Save lokeshh/ae78fc9ddbf1f8c748f555122d832bc7 to your computer and use it in GitHub Desktop.
public class Solution2 {
public static String runToWin(int input1, String[] input2, String input3) {
boolean[] stop = new boolean[input1];
int[] distances = new int[input1];
for (int i = 0; i < input3.length(); i++) {
int d = input3.charAt(i) - '0';
int racer = i % input1;
if (d == 0) {
stop[racer] = true;
}
if (!stop[racer]) {
distances[racer] += d;
}
}
int winner = 0;
int winning_distance = distances[0];
for (int j = 0; j < input1; j++) {
if (distances[j] > winning_distance) {
winning_distance = distances[j];
winner = j;
}
}
return input2[winner] + ":" + winning_distance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment