Created
August 5, 2019 16:21
-
-
Save psaitu/552aaac88ad1f601e9002e9a315606ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import java.util.Arrays; | |
| public class Main { | |
| static long arrayManipulation(int n, int[][] queries) { | |
| int[] arr = new int[n]; | |
| // Arrays.fill(arr, 0); | |
| int m = queries.length; | |
| for(int i = 0; i < m; i++) { | |
| arr[queries[i][0] - 1] += queries[i][2]; | |
| if(queries[i][1] != n) { | |
| arr[queries[i][1]] -= queries[i][2]; | |
| } | |
| } | |
| int max = 0; | |
| int sum = 0; | |
| for(int j = 0; j < n; j++) { | |
| sum += arr[j]; | |
| if(sum > max) { | |
| max = sum; | |
| } | |
| } | |
| return max; | |
| } | |
| public static void main(String[] args) { | |
| /* | |
| * | |
| * Logic | |
| * | |
| * arr = [0, 0, 0, 0] | |
| * | |
| * query1 = 1 3 3 | |
| * arr = [3, 0, 0, -3, 0] | |
| * | |
| * query 2 = 2 4 4 | |
| * arr = [3, 4, 0, -3, -4] | |
| * | |
| * | |
| * | |
| * */ | |
| System.out.println("Hello World!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment