Minimize the maximum difference between heights || Love Babbar DSA sheet

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ก.ย. 2024

ความคิดเห็น • 200

  • @foziezzz1250
    @foziezzz1250 2 ปีที่แล้ว +79

    13:14 So now what I have understood
    we know the usual answer is, In a sorted array, difference between (first element+k ) and (last element -k), is maximum
    adding k and subtracting k is the only way we can bring them closer and thus minimise the difference between them, which is the maximum difference.
    But in cases where K is in order of elements and adding or subtracting K, changes the sorted order, and largest no longer remain largest, and smallest no longer the smallest, then we have to find the correct largest and smallest element.
    we keep them in mi, and ma, they are so far seen smallest(non-negative) and largest values
    and also, we always can either add k or subtract k from a number, so we try both on arr[i] and collect smallest and largest,
    one thing that would come in our mind is what if adding k and subtracting k on same element both worked and become a part of the answer and we can only do only one operation.
    Then we can surely say it won't happen, because if an element subtract by k, is smaller than the smallest element, then definitely it cannot become larger than largest element, only possible for arr[n-1] which is considered in largest.
    and using [i+1] saves an iteration.
    as arr[0]-k is already equal to smallest so avoided.
    and i going max to n-2, avoids calculating arr[i-1]+k, which is already considered in largest
    Now it got more clear after writing an explanation. Hope this helps someone too.

    • @namankumarsharma9187
      @namankumarsharma9187 2 ปีที่แล้ว +28

      this explanation helped me more than this entire video.🤷‍♂️😂

    • @parrotsparadise3914
      @parrotsparadise3914 2 ปีที่แล้ว +2

      Can you explain?
      you are taking arr[0]+k as the smallest....fine..
      But in loop you are doing arr[i+1]-k
      to find minimum
      Whyy? You said you want to minimise the difference which will happen only when we add k to min
      So in loop also you should increment a[i+1]+k ...like you did for smallest

    • @foziezzz1250
      @foziezzz1250 2 ปีที่แล้ว +4

      @@parrotsparadise3914 See this example from GFG
      Input : arr[] = {1, 10, 14, 14, 14, 15}
      k = 6
      Output: Maximum difference is 5
      arr[] = {7, 4, 8, 8, 8, 9} here minimum element is 4
      4 and 9 are actually obtained by subtracting K
      that technique is directly valid on normal case (where k is small)
      but there can be more cases, and the logic inside loop deal with it smartly
      It deserves some thinking,and you are smart enough to do that,maybe start from the base. even I am having trouble right now explaining it really well, but i will think about it tomorrow.🤣
      Check sKSama's minimise the height II video, he explains using numberlines

    • @parrotsparadise3914
      @parrotsparadise3914 2 ปีที่แล้ว +2

      @@foziezzz1250 Lol thanks anyways!

    • @VanshikaSharma-qm7gj
      @VanshikaSharma-qm7gj 2 ปีที่แล้ว +1

      thanks

  • @omkarkawatgi
    @omkarkawatgi 2 ปีที่แล้ว +6

    It was very difficult to grasp only looking at solution code, You made it easy to understand . Thank you!

  • @nandinibagga4857
    @nandinibagga4857 3 ปีที่แล้ว +43

    best solution.. i was searching for this explanation, thanks for uploading!

  • @Aryan-c8p7h
    @Aryan-c8p7h 8 หลายเดือนก่อน +3

    THIS is the correct code passes all the test cases.
    sort(arr,arr+n);
    int ans=arr[n-1]-arr[0];
    int largest=arr[n-1]-k;
    int smallest=arr[0]+k;
    int mi,ma;
    for(int i=1;i

  • @amalkumar256
    @amalkumar256 ปีที่แล้ว +2

    I wasn't able to understand from editorial and other videos so huge thanks to you for clarifying everything brother.

  • @vedantbhenia9085
    @vedantbhenia9085 3 ปีที่แล้ว +7

    well, It's not everyone's cup of tea to explain something like that. kudos to you brother!

  • @unofficialshubham9026
    @unofficialshubham9026 ปีที่แล้ว +2

    If we have a small tower (let say of height = 4 ) and a large tower (height = 6) and we increase the height of small tower and decrease height of large tower (k=3) then smallTowerHeight = 7 and largeTowerHeight = 3 so smaller tower becomes greater than larger tower after the operation.

  • @navnitkumar1919
    @navnitkumar1919 3 ปีที่แล้ว +8

    Mast explanation bro. I mean i am new to competitive. And i was solving dsa 450, and i got code through comments. Tried learning myself, I didn't understand...... but this explanation is beautiful.

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Thank You Navnit
      Happy Coding!!

    • @parrotsparadise3914
      @parrotsparadise3914 2 ปีที่แล้ว

      @@techskeletons7381 you are taking arr[0]+k as the smallest....fine..
      But in loop you are doing arr[i]-k
      to find minimum
      Whyy?? You said you want to minimise the difference
      So in loop also you should increment min...

  • @sugyaneesahu3585
    @sugyaneesahu3585 3 ปีที่แล้ว +9

    Explaining each and every code line was really helpful in understanding the approach implementation. Thanks a lot!

  • @uhee73822
    @uhee73822 3 ปีที่แล้ว +6

    My doubt is why you initialise ans=arr[n-1]-arr[0] ; ??
    why we cant initialise ans= largest-smallest; ????????????????????????????????????????????

    • @ChandraSekhar-tr7sf
      @ChandraSekhar-tr7sf 2 ปีที่แล้ว +1

      this code is just like mugging up

    • @Rajnish-pu8mj
      @Rajnish-pu8mj 3 หลายเดือนก่อน

      It's because the code is sorted and initial the first tower will be lowest and last one would be highest so initial ans would be last-first [they are only largest and smallest] tower after sorting

  • @latewind72
    @latewind72 2 ปีที่แล้ว +4

    Thanks for explaining each line of code in detail! But I want to give a small correction for "if(mi < 0) continue;" line. Instead of saying it as "increasing the difference" we may say that as mi shouldn't be less than 0 as "smallest" is always > 0 and "arr[i+1] - k" is >=0 as k shouldn't be subtracted from the element if it results in a negative number(As stated in the question).

  • @mohamed_bouafif
    @mohamed_bouafif 6 หลายเดือนก่อน +1

    Hello, is it logically correct to calculate the average of the array values .
    Than iterate through the array and check :
    If the value is bigger than the average we check if we substrat k from it it becomes closer to the average value if not we do nothing.
    And we do the same if the value is bigger than the average (but by adding k)
    Than we print max-min

  • @growmore1672
    @growmore1672 2 ปีที่แล้ว

    Int diff = arr[n-1] - arr[0]
    Yeh isliye kiya to handle a edge case of (arr[n-1] + k ) - (arr[0] + k )
    Yeh bhi ek minimum difference ka candidate hai

  • @namansharma5128
    @namansharma5128 2 ปีที่แล้ว +1

    9:58 📢📢🙋‍♂️suppose the heights are 3,4,5 and k=2, so a/c to the algo smallest= 3+2= 5 and largest = 5-2=3, but how it this possible. smallest>largest ??????????

  • @oumaimachattat6675
    @oumaimachattat6675 24 วันที่ผ่านมา

    Thanks a lot for the explanation

  • @kirtik3859
    @kirtik3859 2 ปีที่แล้ว +1

    nice explanation. you teach how each command has a purpose in this program.

  • @parrotsparadise3914
    @parrotsparadise3914 2 ปีที่แล้ว +1

    In this question,
    We DON'T have to minimise the difference between heights!!
    We have to minimise the maximum difference between the heights!
    There's a difference guyss!!
    And he also explained the point wrong. At 13:30

  • @rsrivastav007
    @rsrivastav007 2 ปีที่แล้ว

    you don't actually need the continue statement. if you subtract a negative value from a positive value then it'll always give you a positive value itself and then you can check it with current min difference so current min will in any case be less

  • @bishalmohari8748
    @bishalmohari8748 3 ปีที่แล้ว +12

    Keep up the patience you portrayed here, you'll stand out.

    • @sachinarora6682
      @sachinarora6682 2 ปีที่แล้ว

      It's wrong explaination!
      In video it is explained that min difference would be in the adjacent element, which is wrong. Had the elements been 3,4,9, instead of 3,9, etc, the min difference would be in the 1st and 3rd element!

  • @divyankgupta_12
    @divyankgupta_12 2 ปีที่แล้ว +4

    This solution makes no sense to me, I can't understand why consecutive values are being considered when the question clearly says that we need to compare smallest and the largest tower, what is the guarantee that smallest tower and largest tower is always consecutive (after sorting, increment and decrement)?

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว +1

      The question doesn't make sense it seems [ for you ]

  • @TodayContestSolution
    @TodayContestSolution ปีที่แล้ว

    AQ my perspective the condation if(mi

  • @amaankhan8436
    @amaankhan8436 3 ปีที่แล้ว +5

    great video man but I have one question: why do we have to initialise ans as arr[n-1] - arr[0]? why cant we initialise it as INT_MAX or 0?

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +5

      Hey Bro... We cannot make it 0 because we, in our code taking min of arr with current value in a particular iteration
      Moreover... the min possible value of k is 0
      So what will be the ans when k = 0 it will be arr[n-1] - arr[0]

    • @amaankhan8436
      @amaankhan8436 3 ปีที่แล้ว +2

      @@techskeletons7381 thanks bro understood 👍

  • @bishwajeetsharma3498
    @bishwajeetsharma3498 3 ปีที่แล้ว +6

    what if arr[n-1]-k

    • @ArchanaKumari-hu3ee
      @ArchanaKumari-hu3ee 3 ปีที่แล้ว +1

      in that case diff will be arr[n-1] - arr[0] no need to increment or decrement any array element

  • @dhee.01
    @dhee.01 2 ปีที่แล้ว +2

    Thanks for the walkthrough buddy.Really helpful

  • @prernajain9572
    @prernajain9572 2 ปีที่แล้ว

    Thank you for the video. It's a good and easy approach.

  • @rajkumar-vm6yo
    @rajkumar-vm6yo 3 ปีที่แล้ว +1

    best solution so far
    thank you for the video!!!

  • @shaamidrees6036
    @shaamidrees6036 ปีที่แล้ว

    Thanks bro finally understood after so many videos..

  • @shikher4559
    @shikher4559 14 ชั่วโมงที่ผ่านมา

    your knowledge is commendable but the dry run was not good for beginners

  • @mohammedwaseem8599
    @mohammedwaseem8599 3 ปีที่แล้ว +1

    Thank you so much bro for easy algorithm and simple explanation

  • @parthsalat
    @parthsalat 3 ปีที่แล้ว +2

    Fucking genius explanation

  • @aniruddhachunne3011
    @aniruddhachunne3011 2 ปีที่แล้ว

    so need to sort the array... and make it so complex...

  • @sahebullah2194
    @sahebullah2194 11 หลายเดือนก่อน

    Exact explanation of my silly doubt in this question
    You rock bro 😎

    • @choulvijay8281
      @choulvijay8281 8 หลายเดือนก่อน

      and what was that doubt...can u tell me
      😅

  • @siddhantyadav4531
    @siddhantyadav4531 3 ปีที่แล้ว

    Best solution of this question on You tube 👍👍👍👍 Thanks a lot bro

  • @glenfernandes253
    @glenfernandes253 3 ปีที่แล้ว +4

    Great video man, How do you come up with solutions?

  • @codingcrush
    @codingcrush 2 ปีที่แล้ว

    I salute this code.

  • @rahulbawa6864
    @rahulbawa6864 2 ปีที่แล้ว

    Very well explained. Thanks a lot.

  • @nitinrai5053
    @nitinrai5053 3 ปีที่แล้ว +2

    Very good explanation I appreciate a lot 🔥

  • @venkatgaddam6587
    @venkatgaddam6587 8 ชั่วโมงที่ผ่านมา +1

  • @nirajkumarsingh7725
    @nirajkumarsingh7725 3 ปีที่แล้ว +2

    Neatly explained, but I am still stucked at mi and ma inside for loop... Can you please help me by making the code dry run...

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +11

      I too regret that i did not dry dun the code....
      See in this problem we need minimise the maximum difference between the tower heights so what i am doing is to take each tower increase its height by k and assume it to be the largest so far so that i can check its difference with my current smallest tower and if that difference is minimum so far i update the variable storing the final answer.
      At the end of the code we actually get the largest tower height in ma and smallest tower height in mi and ma-mi gives the minimised max difference of tower heights...
      Please read this again if you cant get it...
      *sorry for late reply*

  • @thefizzshow
    @thefizzshow 2 ปีที่แล้ว

    Thanks for the amazing explanation...

  • @piyushmalav6054
    @piyushmalav6054 3 ปีที่แล้ว +1

    why we are not talking about the case when k is greater than maxValueInArray

  • @loucool1707
    @loucool1707 2 ปีที่แล้ว

    I'm felling like I'm dumb, and this is only considered a easy to medium difficulty problem 🙃

  • @bestdeal3385
    @bestdeal3385 2 ปีที่แล้ว

    omg finally understood this problem thankuu😄

  • @anveshasharma2726
    @anveshasharma2726 2 ปีที่แล้ว

    Great explaination bro keep it up

  • @shashankagarwal9301
    @shashankagarwal9301 3 ปีที่แล้ว

    Thank you so much, I was stuck on it for 2 days

  • @ShivamKendre-fc3su
    @ShivamKendre-fc3su ปีที่แล้ว

    Great explained

  • @crazyzyx5030
    @crazyzyx5030 2 ปีที่แล้ว

    inside for loop, the first two sentence, mi = min(smallest, arr[i+1]-k); here you are taking i+1 but in next line you just taking i , why ?

  • @ashisbhowmik348
    @ashisbhowmik348 3 ปีที่แล้ว +3

    Where is the min and max algorithm

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +2

      I am using std::min and std::max functions predefined in the header file "algorithm" in c++
      min(x,y) returns the min of x and y
      max(x,y) returns the max of x and y
      Also you could have done this if you dont wanna use the predefined methods :
      if(smallest

    • @ashisbhowmik348
      @ashisbhowmik348 3 ปีที่แล้ว +2

      @@techskeletons7381 thank for solving my question❓❓👍👍

  • @sagarbora7768
    @sagarbora7768 2 ปีที่แล้ว

    Thanks bro for gettng thsi inside my head

    • @parrotsparadise3914
      @parrotsparadise3914 2 ปีที่แล้ว

      Can you explain me?
      you are taking arr[0]+k as the smallest....fine..
      But in loop you are doing arr[i]-k
      to find minimum
      Whyy?? You said you want to minimise the difference
      So in loop also you should increment min...

  • @udayjordan4262
    @udayjordan4262 2 ปีที่แล้ว

    yeah everything is right but i have a doubt since int the gfg it is said it is compulsory to perform a +k or -k then why we are not initializing it wit int_max morover it will also not pass the test case in gfg so its a huge bug in question

  • @shubhamjain5813
    @shubhamjain5813 3 ปีที่แล้ว

    thanks for explaining so well

  • @HighEndCruisers1
    @HighEndCruisers1 2 ปีที่แล้ว

    Kya bhai is ka answer is se to bhut simple ho Sakta tha dikkat ye thi k aapne is algorithm ko dekh kr solution dunda

  • @muskanagrawal7428
    @muskanagrawal7428 ปีที่แล้ว

    Can u give one example when there is a case that largest and smallest part in you code ..do not give minimum value?...
    Then what are those value which give min diff on adding or subtracting k, other than doing same with first and last element?

  • @TonyStark-ct8xd
    @TonyStark-ct8xd 3 ปีที่แล้ว

    Thank you bro,it finally worked .

  • @kritidiptoghosh4272
    @kritidiptoghosh4272 2 ปีที่แล้ว

    ok

  • @moneshc6887
    @moneshc6887 2 ปีที่แล้ว

    Gem 🤩

  • @aryansinha1818
    @aryansinha1818 ปีที่แล้ว

    What an awesome explanation. Thanks a ton man.

  • @codingfriend2058
    @codingfriend2058 2 ปีที่แล้ว +1

    Jeegs

  • @sinchansaha3803
    @sinchansaha3803 2 ปีที่แล้ว

    Elaborative explanation great!

  • @rohitkanojiya5880
    @rohitkanojiya5880 3 ปีที่แล้ว

    🙏Thanks for Great Explanation

  • @DinoSnore
    @DinoSnore 3 ปีที่แล้ว

    What if the elements are 3 4 12 16 17
    And k = 5
    Then smallest will be 3+5 =8
    And 4 will be skipped bcoz 4-5 will be negative Hence the minimum number will remain 8

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      The minimum will not remain 8 my friend...
      The ans for this particular output is 5 and my code also giving this output.
      Please watch the video again and undertsand.

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Let me clear one more thing...
      We always take minimum of (smallest and arr[i+1]-k) and these two things never become negative because in my code i continue to next iteration as soon as mi becomes less than 0

    • @DinoSnore
      @DinoSnore 3 ปีที่แล้ว

      @@techskeletons7381 that’s what i am saying
      Won’t 4 be skipped that way

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Yes thats what we need... 4 will never... i repeat... never participate in the pair that gives minimum max difference if we subtract 5 from it!
      Its very logical!

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      It will participate only when we add 5 to it but not when we subtract 5 from it

  • @jaagoindia-xn7rp
    @jaagoindia-xn7rp 2 ปีที่แล้ว

    Great explaination

  • @nupurkumari9725
    @nupurkumari9725 3 ปีที่แล้ว

    Go for it ..you explain well

  • @ka9133
    @ka9133 ปีที่แล้ว

    He hasn't explained anything just justifying the code but not intuition.

  • @shivam4you744
    @shivam4you744 3 ปีที่แล้ว

    Gjb explanation

  • @Faixtel
    @Faixtel 2 ปีที่แล้ว

    thank you soo much bro...

  • @tanaykamath1415
    @tanaykamath1415 2 ปีที่แล้ว

    great soln. 👏👏

  • @its_neel_ok
    @its_neel_ok 3 ปีที่แล้ว +1

    why is the loop form 0 to n-1 instead of 0 to n ???

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +2

      Because we are taking arr[i+1] and hence it will go to last index
      Also we will run out of bounds and it will throw an error when i is at last and we try to access arr[i+1]

    • @its_neel_ok
      @its_neel_ok 3 ปีที่แล้ว

      @@techskeletons7381 thanks a lot .❤️

    • @softwarehacks6604
      @softwarehacks6604 2 ปีที่แล้ว

      Sir,what is it's time complexity??

    • @its_neel_ok
      @its_neel_ok 2 ปีที่แล้ว

      @@softwarehacks6604 o(n)

  • @saurabhsain2153
    @saurabhsain2153 3 ปีที่แล้ว +1

    You are great bro👍

  • @tanishsharma5440
    @tanishsharma5440 2 ปีที่แล้ว

    Thankyou brother

  • @Jk-tr1fb
    @Jk-tr1fb 3 ปีที่แล้ว

    Great explanation , what's the answer of the array which u took ?

  • @shreyankshrestha9274
    @shreyankshrestha9274 3 ปีที่แล้ว

    thanks bro keep makin such videos

  • @poojaupadhyay6364
    @poojaupadhyay6364 2 ปีที่แล้ว

    Best solution

  • @lukeshsingh2194
    @lukeshsingh2194 3 ปีที่แล้ว

    Excellent explanation!

  • @pritamsaha1387
    @pritamsaha1387 3 ปีที่แล้ว +1

    I understand the whole part but the min and Max part in for loop, I don't get it please can you explain this

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +1

      i am finding new candidates so that i get a new minimized max difference
      if you are still confused please watch the video again as I explained it!

  • @soumakdalapati2026
    @soumakdalapati2026 3 ปีที่แล้ว

    nicely explained..🙏🙏

  • @sanidhyasrivastava3816
    @sanidhyasrivastava3816 3 ปีที่แล้ว

    Great Explanation

  • @vamthisside6253
    @vamthisside6253 3 ปีที่แล้ว +1

    Genius bro

  • @TaiChiSWAG
    @TaiChiSWAG 3 ปีที่แล้ว +1

    At 11:23 I'm not able to get current largest case and where you are comparing
    ma = max(largest, arr[i]+k);
    Please help.

    • @_just_for_fun_4472
      @_just_for_fun_4472 3 ปีที่แล้ว

      +1

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +3

      See in this problem we need minimise the maximum difference between the tower heights so what i am doing is to take each tower increase its height by k and assume it to be the largest so far so that i can check its difference with my current smallest tower and if that difference is minimum so far i update the variable storing the final answer.
      At the end of the code we actually get the largest tower height in ma and smallest tower height in mi and ma-mi gives the minimised max difference of tower heights...
      Please read this again if you cant get it...
      *sorry for late reply*

    • @_just_for_fun_4472
      @_just_for_fun_4472 3 ปีที่แล้ว

      @@techskeletons7381 hey! Actually the point where i am stuck is..(11:21).you said we compare the first or previous element with the largest one and the second or the next element with the smallest one.....but as acc to me and also acc to from (8:01) the (previous or the first one will be the small one so we should compare it with the SMALLEST) and ( the next or the second one in those two consecutive elements should be compared with the LARGEST one so that we get the optimized max and min element in each iteration ) soo..you see i am just understanding it in opposite direction...and i need some help...

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +3

      Thanks for coming back to us...
      Actually whenever we increase the height of a tower we assume it to be the new largest (as it will approach more close to max) and hence we compare it with max or largest tower.
      Similarly when we decrease height of i+1th tower we assume it to be smallest tower and we compare it with mi.
      Also you see this that after sorting we are iterating over the tower heights in for loop and in every next iteration the tower whose height was increased in previous iteration is now decreased in next iteration so we are actually increasing and decreasing the heights of each tower and then comparing them with mi and ma and update the ans accordingly.

  • @rohandsouza9147
    @rohandsouza9147 3 ปีที่แล้ว

    Why do we start mi = min(smallest,arr[i+1]-k) there's a possibility that arr[0]-k is the smallest element

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Lets assume the heights are 1,4,7 and k =4
      Now you cannot decrease the height of tower of height 1 as it will become negative moreover i already explained in the video why we should increase the height of smallest tower and decrease the height of tallest tower... please watch the video again...

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Btw for this particular example the ans is 2 (when we modify the array to 6 1 3)

  • @swatantrapatel7608
    @swatantrapatel7608 2 ปีที่แล้ว

    Nice ❤️

  • @swaroopkv4540
    @swaroopkv4540 ปีที่แล้ว

    Recursive solution for this?

  • @codingcrush
    @codingcrush 2 ปีที่แล้ว

    hey brother can you tell me where are you currently doing in studies
    and did you code this by yourself

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว

      I am done with my studies and recently joined a product based company, and i did code that by myself!
      Practice dsa and solve problems regularly, you will also develop skills to code such solutions.
      All the best!

  • @nott__aceu4857
    @nott__aceu4857 3 ปีที่แล้ว

    understood

  • @ashitoshfating7154
    @ashitoshfating7154 2 ปีที่แล้ว

    I have a doubt how can you calculate ans in each iteration bcz ma & mi are max & min elements seen so far in arr till index i ,but the ques says min diff between max & min of complete array.

  • @abuosamashaikh5306
    @abuosamashaikh5306 2 ปีที่แล้ว

    I am getting wrong output.
    My array is {1,5,10} and k is 6.
    The min difference should be 3 but i am getting 7

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว

      Check again your code.
      Its giving 3 only!

    • @abuosamashaikh5306
      @abuosamashaikh5306 2 ปีที่แล้ว

      @@techskeletons7381 it's giving me 7 only except when i am doing ans=largest-smallest;
      Then i am getting - 3

  • @Shivamkumar-ue4hl
    @Shivamkumar-ue4hl 2 ปีที่แล้ว

    can soomeone explain how the bruteforce complexity is 2^n ?

  • @YashMaurya
    @YashMaurya 3 ปีที่แล้ว

    why are you subtracting k in mi = min(smallest,arr[i+1]-k) while adding k in smallest?

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +4

      Because when we subtract k it will become a new candidate for next min and hence we are comparing with smallest

  • @praharshsingh2095
    @praharshsingh2095 3 ปีที่แล้ว

    Awesome buddy

  • @akshatrajput521
    @akshatrajput521 3 ปีที่แล้ว

    Sort esi hi likhte hai...
    Sahi hai tu

  • @amantarar9077
    @amantarar9077 2 ปีที่แล้ว

    apni practice maintain krne ke liye aap english me zoor lagare ho otherwise hindi me 100x jyada ache se smjh aaega

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว

      There are so many who dont understand hindi

    • @amantarar9077
      @amantarar9077 2 ปีที่แล้ว

      @@techskeletons7381 arey sir 😂,India hai
      9/10 coder in India understands Hindi comfortably

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว

      Tamil Telugu Kannada, so 9/10, no bro

  • @Knowledgeduniya1432
    @Knowledgeduniya1432 2 ปีที่แล้ว

    Thankyou bhai per aise soch kse lete ho

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว

      Practice

    • @Knowledgeduniya1432
      @Knowledgeduniya1432 2 ปีที่แล้ว

      @@techskeletons7381 bhaiya khub se khub bruetforce soch paaga optimal kse sochu pls btao aaj ss aapki videos dekhuga helpful LG rhi♥️🙏🏻

    • @techskeletons7381
      @techskeletons7381  2 ปีที่แล้ว +1

      Most of the problems are based on some pattern or some specific concept, keep practicing you wont get initially but once you keep practicing you will get it

  • @codeandtalk6
    @codeandtalk6 3 ปีที่แล้ว +1

    Code is failing for some test cases

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      Submitting on GFG?

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว +1

      I just checked
      Its accepted
      All test case passed
      I submitted on GFG
      Make sure you sorted the array and check all conditions.

    • @codeandtalk6
      @codeandtalk6 3 ปีที่แล้ว

      K thank you I did some mistakes

  • @Jk-tr1fb
    @Jk-tr1fb 3 ปีที่แล้ว

    Actually ,I'm confused why we're sorting the array

    • @techskeletons7381
      @techskeletons7381  3 ปีที่แล้ว

      I explained in the video why i sorted the array, kindly watch again!

    • @Jk-tr1fb
      @Jk-tr1fb 3 ปีที่แล้ว

      @@techskeletons7381 I understand ,thanks

  • @navin55532
    @navin55532 4 หลายเดือนก่อน

    bad explanation but 100 marks for your effort

  • @VinayKumarPandey782
    @VinayKumarPandey782 3 ปีที่แล้ว

    greatt bro

  • @ishumiglani0
    @ishumiglani0 2 ปีที่แล้ว

    Kuch smjh ni aaya bro

  • @ap331
    @ap331 3 ปีที่แล้ว

    Great in explaining You earned a sub !

  • @aakashparmar560
    @aakashparmar560 3 ปีที่แล้ว

    Not working for me as of now.!!

  • @lalit-singh-bisht
    @lalit-singh-bisht ปีที่แล้ว

    kuch samajh nhi aaya