We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Array Manipulation
- Discussions
Array Manipulation
Array Manipulation
Sort by
recency
|
21 Discussions
|
Please Login in order to post a comment
Single Pass O(N) Functional Sol'n
Understand the Difference Array Trick - super simple and effective!
Make arr size n+1 so we can add to end if its the Last item (or ignore)
only Mark the Starts with +query and mark the end+1 index with a -ve value [100, 500 , 0 , 200 , -100 , -500 , 0 , -200 ]
Then simply compute the Prefix Array in a Single Pass
C# using a dictionary:
You can also pass with square root decomposition, as the array is very large you do need to first reduce the array to the key indexes first (10e7 array to only 400k), should have used a bigger m to avoid this solution
is the sample input and output given in the question is correct ?? .... if correct can anyone help me understand it?? how it's output will be 200???
public static long arrayManipulation(int n, List> queries) { // Write your code here long[] arr = new long[n+2]; for(int i = 0; i < queries.size(); i++) { int a = queries.get(i).get(0); int b = queries.get(i).get(1); int k = queries.get(i).get(2);