Here, 'k' can be any integer. My O(nlogn) solution is as follows : https://ideone.com/Ff3CcO Is there any O(n) algorithm for above? Thanks. Note: 1)I've done my research. 2)No, this problem does not belong to any ongoing contest in the world :) asked 23 Jan, 12:55

Yes, we can! :) Precalc prefix and suffix negative sums sorted by sum and length. It can be done at O(n), because we add new sum to already sorted array only if this one is smaller than last. Use two pointers technics to parse all pretenders and choose the longest. answered 24 Jan, 02:30

can u please send the link of the question : ) answered 24 Jan, 21:05
Question is:https://www.hackerearth.com/practice/algorithms/searching/binarysearch/practiceproblems/algorithm/superiorsubstringdeccircuitse51b3c27/ But after we reach the last step of the solution we realize that we have to find the length of the longest subarray with sum>2
(24 Jan, 22:55)

try variant of Kadane algorithm.
DOES NOT WORK