@shawngao Thanks for the response. What i meant with the stmt, was that we are storing the sum whatever it might be. Since its a map... i get that we are only storing once. But my question, and I could have been clearer was How does a particular sum value 2 in my example indicate an even number of 0's and 1's. I would assume that a sum == 0 would indicate that. Again the program clearly works, its just a gap in my understanding that I am trying to fill.
pradyot.dhulipala
@pradyot.dhulipala
Posts made by pradyot.dhulipala

RE: Easy Java O(n) Solution, PreSum + HashMap

RE: C++ Dynamic Programming simple and fast solution (4ms) with optimization
A minor observation. When I first saw this explanation "dp[i] is set to true if a valid word (word sequence) ends there" I assumed i meant index into string. But I believe this actually means length of the substring being matched. thats why you can set dp[0] = true since any zero length string can be considered valid.

RE: Easy Java O(n) Solution, PreSum + HashMap
"SUM[i, j] == 0 then we know there are even number of 1 and 1 between index i and j". This makes sense to me. However I noticed we are storing the sum regardless of its value on the map. And we also calculate the max length everytime we see the same sum twice. For eg:
[0,0,1,0,0,0,1,1] the max length 6 is actually returned on the stored sum value 2. I know I am likely missing something obvious here, but I'd really appreciate it if someone could point it out,. 
RE: Merge two interval lists
@agave I Imagine though that at the end(once all merges are done). You would have to make another pass through the list to ensure there is no overlap

RE: 36 easy lines, C++, Java, Python, Ruby
What an elegant solution. Taking full advantage of the sorted nature.
A minor optimization to avoid checking if i<2 in the loop.int removeDuplicates(vector<int>& nums) { //No deletions required. if (nums.size()<=2){ return nums.size(); } int valid_index = 2; for (int i=2;i<nums.size();++i){ if (nums[i] > nums[valid_index2]){ nums[valid_index++] = nums[i]; } } return valid_index; }