Created
June 20, 2018 11:20
-
-
Save lokeshh/ae78fc9ddbf1f8c748f555122d832bc7 to your computer and use it in GitHub Desktop.
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 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