[Python] Easy PREFIX SUM
Maximum Erasure Value\n\n\nLets assume for array [1, 2, 5, 2, 5, 1] \n\n Padding :- we add 0 in the beginning of array to prevent Index_Out_Bound error then arr
# Maximum Erasure Value\n\n\nLets assume for array *[1, 2, 5, 2, 5, 1]* \n\n* `Padding :- ` we add 0 in the beginning of array to prevent **Index_Out_Bound** error then array **nums** becomes *[0, 1, 2, 5, 2, 5, 1]*\n* `Index Array :-` we create the index array **Idxarr** which can be formed of the length of maximum element **mx** in the array , since give ```1 <= nums[i] <= 10^4``` \xA0it may reach max at *10^4* so its **time and space complexity is `O(max(10^4, length of array)`** \xA0which is same even if the array length is > 10^5 i.e. `O(N)` , so mx=5 then idxarr becomes *[0,0,0,0,0,0]*(mx+1 i.e. 6)\n* `Prefix sum :- ` Then we form the prefix sum array **pre** becomes *[0, 1, 3, 8, 10, 15, 16]*\n* `Important Variables:- ` Now take **ans=0** to store result and **last=0** to store the index of the last time where *uniqueness* started\n\n So in the final loop **idxarr** keeps on updating index of every element from which update **last** and thus difference between sum untill now and sum till the last index(**last**) gives us sum of unique sub array *(prefix differences at current and last index)*. The max of these differences updated in **ans**.\n \n *Please upvote if you like the solution and comment if have any  queries* .\n \n```\nclass Solution:\n    def maximumUniqueSubarray(self, nums: List[int]) -> int:\n        nums = [0]+nums#padding\n        \n        n = len(nums)\n        mx = max(nums)\n        \n        Idxarr = [0]*(mx+1)#Index Array\n        \n        #prefix sum\n        pre = [0]*n\n        for i in range(1, n):\n            pre[i] = pre[i-1]+nums[i]\n        \n        ans = last = 0\n        for i in range(1, n):\n            last = max(last, Idxarr[nums[i]])\n            ans = max(ans, pre[i]-pre[last])\n            Idxarr[nums[i]]=i\n        return ans\n```
['Prefix Sum', 'Python']