Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 11, 2021 16:42
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 vrat28/84e5436a636dec9aa73eb2a7168d9a73 to your computer and use it in GitHub Desktop.
Save vrat28/84e5436a636dec9aa73eb2a7168d9a73 to your computer and use it in GitHub Desktop.
Max Score(Sliding Window: Java)
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