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.
- Mini-Max Sum
- Discussions
Mini-Max Sum
Mini-Max Sum
Sort by
recency
|
342 Discussions
|
Please Login in order to post a comment
class Result {
// Loop is working for n-1 times means 4 times and not include 4 in it. for (int i = 0; i < 4; i++) { // adding starting 0 to 3 elements as they are smallest minimum += arr.get(i); // adding ending 4 elements because they are biggest maximum += arr.get(arr.size() - 1 - i); }
}
I have solved the problem without using any builtin methods such as (sort,min,max).And this logic takes O(n) time complexity.if i use sort() method then the logic take lesser time complexity but i aim to write the code without using any predefined methods.
long sum=0; int min=arr.get(0); int max=arr.get(0);
I've read multiple Java Solutions using Collections.sort on the array. I know it doesn't really matter for this problem where the array is always of size 5, but it makes more sense just to iterate through the array one time:
`
Hi, my code seems to be correct almost all the cases except one. the arr = [5, 5, 5, 5, 5], so I tried to account for the fact that the values might be the same (or at least attempted) and I am still struggling. Could someone please explain what it is I am doing wrong? Thanks in advance :) CODE:
def miniMaxSum(arr):