You are viewing a single comment's thread. Return to all comments →
TreeSet<Long> ts = new TreeSet<>(); long rem=0,max=0; for(int i=0;i<a.size();i++){ rem = (rem +(a.get(i)))%m; max = Math.max(max,rem); if(ts.higher(rem)!=null){ max = Math.max(max,(rem+m-(ts.higher(rem)))); } ts.add(rem); } return max;
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Subarray Sum
You are viewing a single comment's thread. Return to all comments →