Minimum Subarray which is larger than a Key
问题 I have an array of integers (not necessarily sorted), and I want to find a contiguous subarray which sum of its values are minimum, but larger than a specific value K e.g. : input : array : {1,2,4,9,5} , Key value : 10 output : {4,9} I know it's easy to do this in O(n ^ 2) but I want to do this in O(n) My idea : I couldn't find anyway to this in O(n) but all I could think was of O(n^2) time complexity. 回答1: Let's assume that it can only have positive values. Then it's easy. The solution is