Harry loves numbers in the range [m1, m2] (m1 and m2 included). carry decides to gift harry
Fantastic news! We've Found the answer you've been seeking!
Question:
Harry loves numbers in the range [m1, m2] (m1 and m2 included). carry decides to gift harry an array of numbers for his birthday. harry wants to find the number of pairs of indices [l, r] for which the sum of all the elements in the range [l, r] lies between m1 and m2.
1.Come up with an algorithm with a worst case complexity of O(N2).
2.Now improvise this algorithm, assuming all numbers are positive integers.
3.What if the numbers could be negative as well? Can you think of an O(nlogn) solution in this case? (Hint: use sorting)
4.Write the java code for third part.
Related Book For
South Western Federal Taxation 2018 Essentials Of Taxation Individuals And Business Entities
ISBN: 9781337386173
21st Edition
Authors: William A. Raabe, James C. Young, Annette Nellen, David M. Maloney
Posted Date: