Maximum Sum of Subarray Close to K
Given an array, find the maximum sum of subarray close to k but not larger than k.
Java Solution
public int getLargestSumCloseToK(int[] arr, int k){ int sum=0; TreeSet<Integer> set = new TreeSet<Integer>(); int result=Integer.MIN_VALUE; set.add(0); for(int i=0; i<arr.length; i++){ sum=sum+arr[i]; Integer ceiling = set.ceiling(sumk); if(ceiling!=null){ result = Math.max(result, sumceiling); } set.add(sum); } return result; } 
<pre><code> String foo = "bar"; </code></pre>

ab