We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Saw some discussions on the approach using ordered/sorted set (TreeSet in Java) here and most of the implementations claimed to have O(nlog**n**) complexity but not O(nlog**m**) (where n is array's size -- up to 10^5, and m is range of value of m -- up to 10^14) so I'm wondering if I missed anything.
Here is my implementation anw.
publicstaticlongmaximumSum(List<Long>a,longm){// Write your code hereTreeSet<Long>set=newTreeSet<>();longmod=0,max=0;for(longnum:a){mod=(mod+num%m)%m;max=mod>max?mod:max;Longnext=set.ceiling(mod+1);if(next!=null){max=Math.max(max,m-(next-mod));}set.add(mod);}returnmax;}
Cookie support is required to access HackerRank
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 →
Saw some discussions on the approach using ordered/sorted set (TreeSet in Java) here and most of the implementations claimed to have O(nlog**n**) complexity but not O(nlog**m**) (where
n
is array's size -- up to 10^5, andm
is range of value ofm
-- up to 10^14) so I'm wondering if I missed anything.Here is my implementation anw.