Mini-Max Sum - HackerRank Solution (Java)

  Рет қаралды 18,334

daose

daose

Күн бұрын

Watch out for overflow!
HackerRank Algorithm: Warmup - Mini-Max Sum (Java)
----------------------------------
Try it yourself here
www.hackerrank...
Previous video on overflow
• A Very Big Sum - Hacke...
HackerRank playlist
• HackerRank Solutions -...

Пікірлер: 22
@daose
@daose 4 жыл бұрын
First time submitting this I glazed over the constraints and definitely overflowed...
@CyberZeo
@CyberZeo 7 ай бұрын
what was a good explanation, thank you 👍
@abhis7478
@abhis7478 2 жыл бұрын
class Result { public static void miniMaxSum(List arr) { // Write your code here long sum=0; long max=Long.MIN_VALUE; long min=Long.MAX_VALUE; for(int i=0;i
@mwildanarya
@mwildanarya Жыл бұрын
why is yours O(2n) and not O(n^2)? sorry to ask because im new to this.
@اناهنا-ب3و
@اناهنا-ب3و Жыл бұрын
When I started this problem, I chose Java 7, but the class name was different than I used to work with and also than yours: It starts like this: public static void miniMaxSum(List arr) { I change the List arr to = int [] arr but give me an error : ====== ERROR ====== Solution.java:43: error: incompatible types: List cannot be converted to int[] Result.miniMaxSum(arr); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error ====== END ERROR ====== How can I fix this problem?
@junaidahmed8594
@junaidahmed8594 3 жыл бұрын
Amazing content, Keep up the awesome work
@aimang1891
@aimang1891 Жыл бұрын
public static void miniMaxSum(List arr) { long min = arr.get(0); long max = arr.get(0); long totalSum = 0; for(int n : arr){ totalSum += n; if(n < min) min = n; if(n > max) max = n; } System.out.println((totalSum-max) + " " + (totalSum-min)); }
@BrunoHenrique-vd1ry
@BrunoHenrique-vd1ry 8 ай бұрын
Great content!!!
@tejaschavan007
@tejaschavan007 Жыл бұрын
superrr🤖🤖
@aryanjain4571
@aryanjain4571 4 жыл бұрын
Great
@deepanshukhorwal8938
@deepanshukhorwal8938 3 жыл бұрын
thanks
@satarh709
@satarh709 Жыл бұрын
I think this is a not optimal solution, I just sorted the array and based of that you know where the min 4 are and max 4 by definition.
@mrcricketanalyst
@mrcricketanalyst Жыл бұрын
sort will take nlogn tc this is linear
@ritchievales
@ritchievales Жыл бұрын
@@mrcricketanalyst this! I came to look a solution here to see if I can improve my code getting rid of the sort method, this did the trick. thanks!
@eoghanfeighery7383
@eoghanfeighery7383 3 жыл бұрын
How do you do it with List arr in the public static header?
@jagdishsurin8628
@jagdishsurin8628 3 жыл бұрын
Same problem facing
@josefernandoperea2848
@josefernandoperea2848 2 жыл бұрын
A bit late, but sure it will help other person. Instead of using arr[0] you should use arr.get(0);
@Conormcnproductions
@Conormcnproductions 2 жыл бұрын
this is how I did it and it passes every test case: static long min, max; public static void miniMaxSum(List arr) { // Write your code here Collections.sort(arr); for(int i = 0; i
@pandeyamit8777
@pandeyamit8777 2 жыл бұрын
voice of video is too low
@ilichnoise
@ilichnoise 2 жыл бұрын
Only works for few cases in currently test need to change to long var. public static void miniMaxSum(List arr) { // Write your code here int max=arr.get(0); int min=arr.get(0); int total=0; for(int num:arr){ total+=num; if(num>max) max=num; if(num
@LYJManchesterUnited
@LYJManchesterUnited Жыл бұрын
class Result { public static void miniMaxSum(List arr) { Collections.sort(arr); // Sort the array in ascending order long minSum = 0; long maxSum = 0; // Calculate the minimum sum minSum = arr.get(0)+arr.get(1)+arr.get(2)+arr.get(3); maxSum = arr.get(1)+arr.get(2)+arr.get(3)+arr.get(4); System.out.println(minSum + " " + maxSum); } } why tf this doesn't work???!
Best Hacker Rank Time Conversion Java Solution
13:53
Algorithms Explained
Рет қаралды 3,7 М.
How To Solve Mini-Max Sum HackerRank Problem [Trick Revealed]
11:23
JAVAAID - Coding Interview Preparation
Рет қаралды 35 М.
It's the natural ones that are the most beautiful#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 22 МЛН
Сигма бой не стал морожкой
00:30
КРУТОЙ ПАПА на
Рет қаралды 10 МЛН
Боксёр воспитал дикого бойца!
01:36
МИНУС БАЛЛ
Рет қаралды 4,9 МЛН
Шаурма с сюрпризом
00:16
Новостной Гусь
Рет қаралды 6 МЛН
Simplifying Higher Ed Communication with AI Webinar
53:50
Tic Tac Toe Game in Java - Full Tutorial with Source
51:39
Coding with John
Рет қаралды 77 М.
Staircase - HackerRank Solution (Java)
5:52
daose
Рет қаралды 10 М.
HackerRank | Problem Solving | Forming a magic square
9:32
Anurag Patel
Рет қаралды 22 М.
Winning Facebook (Meta) Hacker Cup Qual Round 2022?
53:55
Neal Wu
Рет қаралды 2,6 МЛН
Diagonal Difference - HackerRank Solution (Java)
14:45
daose
Рет қаралды 15 М.
Learn React In 30 Minutes
27:16
Web Dev Simplified
Рет қаралды 1,3 МЛН
It's the natural ones that are the most beautiful#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 22 МЛН