Untitled
fn(nums,k) { map psum_index_map; psum = 0; maxlen = 0; psum_index_map.add(0,0); for(i=0->n-1) { psum += arr[i]; rem_sum = psum - k; if(psum_index_map.containsKey(rem_sum)) { maxLen = Max(maxLen,i - map.get(rem_sum) + 1); } if(psum_index_map.containsKey(psum)) { map.put(psum,i); } } return maxLen; }
Leave a Comment