Google | Phone Interview | L4
Anonymous User
787

Given an array of n matchbox, select two ranges of matchboxes such that the sum of matchsticks in each range is equal to K and the ranges should not be overlapping. If there are mutiple ranges find the one which has the least number of boxes. If there are multiple ranges with above condition find the first two ranges.

Example:
arr = 1 2 2 3 4 6 3 1 4 2 8, k = 5
Ans: [(2,3), (7,8)]
arr[2] + arr[3] = 2 + 3 = 5
arr[7] + arr[8] = 1 + 4 = 5

Please let me know if some part of it is not clear

Comments (2)