[DAY3]Array Manipulation

Sherlock Chiou
1 min readOct 14, 2019

--

https://www.hackerrank.com/challenges/crush/problem…

Solution 1: Use an array to record the value in each position after a query is done. Time complexity would be O(N²).

Solution 2: Only recording the change of the value. If a query is adding value 2 from position 2 to 5. Then we add 2 to the value of position 2 and minus 2 from the value of position 6. And we can get the maximum value by recording a temp maximum variable while traversing the array. The time complexity would be O(N).

--

--

Sherlock Chiou
Sherlock Chiou

Written by Sherlock Chiou

Be Effective and Optimize for Learning

No responses yet