Algorithm · Google · Hard
Given an integer array nums and an integer k, find a non-empty contiguous segment nums[l..r] whose sum equals k. Return [bestLen, l, r], where bestLen = r - l + 1 is the length of that segment. Among all valid segments with the greatest length: choose the one with the smallest starting index l; if the starting index is also tied, choose the smallest ending index r. If no contiguous segment sums exactly to k, return [0, -1, -1]. First describe a correct $$O(n^2)$$ brute-force…
Checking your access…