1509. Minimum Difference Between Largest and Smallest Value in Three Moves Leetcode daily challenge

  Рет қаралды 3,133

shashCode

shashCode

Күн бұрын

Пікірлер: 27
@kumaraniket1640
@kumaraniket1640 3 ай бұрын
To be very honeest very well and pin point explanation
@deluluvish
@deluluvish 3 ай бұрын
class Solution { public int minDifference(int[] nums) { int n = nums.length; // Step 1: Get the length of the array. if (n
@shashwat_tiwari_st
@shashwat_tiwari_st 3 ай бұрын
Single loop looks neat!👏👌
@codingwave56
@codingwave56 3 ай бұрын
cool
@adityamittal8697
@adityamittal8697 3 ай бұрын
very nice and neat explaination , thank you buddy 👍👍
@OnstreamGaming
@OnstreamGaming 3 ай бұрын
Beautiful explanation , i always look into your solution and become able to write code on my own ,
@POOJASINGH-bk8hg
@POOJASINGH-bk8hg 3 ай бұрын
Super easy solution, Thanks
@AnkushPundir-hh2sn
@AnkushPundir-hh2sn 3 ай бұрын
without using sorting i get the four minimum and four maximum values class Solution { public int minDifference(int[] nums) { if (nums.length < 5) { return 0; } // Initialize the four smallest and four largest values int min1 = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE, min3 = Integer.MAX_VALUE, min4 = Integer.MAX_VALUE; int max1 = Integer.MIN_VALUE, max2 = Integer.MIN_VALUE, max3 = Integer.MIN_VALUE, max4 = Integer.MIN_VALUE; for (int num : nums) { // Update the four smallest values if (num < min1) { min4 = min3; min3 = min2; min2 = min1; min1 = num; } else if (num < min2) { min4 = min3; min3 = min2; min2 = num; } else if (num < min3) { min4 = min3; min3 = num; } else if (num < min4) { min4 = num; } // Update the four largest values if (num > max1) { max4 = max3; max3 = max2; max2 = max1; max1 = num; } else if (num > max2) { max4 = max3; max3 = max2; max2 = num; } else if (num > max3) { max4 = max3; max3 = num; } else if (num > max4) { max4 = num; } } // Calculate the minimum difference after removing up to 3 elements int a = max4 - min1; int b = max3 - min2; int c = max2 - min3; int d = max1 - min4; return Math.min(Math.min(a, b), Math.min(c, d)); } }
@subhankarkanrar9494
@subhankarkanrar9494 3 ай бұрын
Very good explanation. Ek bachhe ko bhi samajh aa jayega Aisa explanation. ❤
@techwech8265
@techwech8265 3 ай бұрын
Yrr Awesome explanation brother always waiting for your video even after solving the problem by own ❤
@RohitKumar-dz8dh
@RohitKumar-dz8dh 3 ай бұрын
Thanks 😊
@Nishant89-i2z
@Nishant89-i2z 3 ай бұрын
kal channel mila aur aaj se daily problem solving continue pura month solve karunga
@aggarwalsachin4854
@aggarwalsachin4854 3 ай бұрын
brilliant logic!!
@TheFaheemiQuasar
@TheFaheemiQuasar 3 ай бұрын
hats off for this explanation!!
@GirjeshSharma-zv3xo
@GirjeshSharma-zv3xo 3 ай бұрын
please continue this series love from canada🥰
@MohammedHasmi577
@MohammedHasmi577 3 ай бұрын
Amazing explanation sir
@_phonesense
@_phonesense 3 ай бұрын
You explains really well bhaiya.
@NishantPandat-l3q
@NishantPandat-l3q 3 ай бұрын
good explain sir
@adarshjain3058
@adarshjain3058 3 ай бұрын
dudee...plzz plz plzzzz roz ke dcc ke solutions dalna shuru kar do yaarr/...bahout sexy explanation mann
@PrakashRai-ff3pr
@PrakashRai-ff3pr 3 ай бұрын
so after sorting we only need to change the element size by there next value??
@priyanshkumar17
@priyanshkumar17 3 ай бұрын
Bhaiya, please make a video on Leetcode 2035 problem. I'm stuck on this problem since 2 weeks.
@mr.nishantawasthi4402
@mr.nishantawasthi4402 3 ай бұрын
Osm explain sir
@VivekSingh-bx6ig
@VivekSingh-bx6ig 3 ай бұрын
How to prove that there are only 4 cases ?
@AkashRoy-do2dg
@AkashRoy-do2dg 3 ай бұрын
its simple combinatorics as we can change only 3 positions and we can only choose the positions from the begin and the end. now the distributions possible are -> 3 from front 0 from last, 2 from front 1 from last,1 from front 2 from last , 0 from front and 3 from last. you can't make any other possible distribution.
@aggarwalsachin4854
@aggarwalsachin4854 3 ай бұрын
3:10 🤣🤣🤣
@kamranwarsi12b22
@kamranwarsi12b22 3 ай бұрын
3:09 💀
@Pratikk_Rathod
@Pratikk_Rathod 3 ай бұрын
Noise
小丑揭穿坏人的阴谋 #小丑 #天使 #shorts
00:35
好人小丑
Рет қаралды 10 МЛН
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 355 М.
SISTER EXPOSED MY MAGIC @Whoispelagheya
00:45
MasomkaMagic
Рет қаралды 18 МЛН
小丑揭穿坏人的阴谋 #小丑 #天使 #shorts
00:35
好人小丑
Рет қаралды 10 МЛН