Created
May 11, 2021 16:42
-
-
Save vrat28/84e5436a636dec9aa73eb2a7168d9a73 to your computer and use it in GitHub Desktop.
Max Score(Sliding Window: Java)
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
class Solution { | |
public int maxScore(int[] C, int K) { | |
int total = 0; | |
for (int i = 0; i < K; i++) total += C[i]; | |
int best = total; | |
for (int i = K - 1, j = C.length - 1; i >= 0; i--, j--) { | |
total += C[j] - C[i]; | |
best = Math.max(best, total); | |
} | |
return best; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment