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

Поделиться
HTML-код
  • Опубликовано: 1 июл 2024
  • Problem:
    1509. Minimum Difference Between Largest and Smallest Value in Three
    Problem Statement:
    You are given an integer array nums.
    In one move, you can choose one element of nums and change it to any value.
    Return the minimum difference between the largest and smallest value of nums after performing at most three moves.
    Problem Link:
    leetcode.com/problems/minimum...
    Graph Playlist:
    • Graph Data Structure S...
    Java Plus DSA Placement Course Playlist:
    • Java and DSA Course Pl...
    Java Plus DSA Sheet:
    docs.google.com/spreadsheets/...
    Notes:
    github.com/Tiwarishashwat/Jav...
    Telegram Link:
    shashwattiwari.page.link/tele...
    Ultimate Recursion Series Playlist:
    • Recursion and Backtrac...
    Instagram Handle: (@shashwat_tiwari_st)
    shashwattiwari.page.link/shas...
    Samsung Interview Experience:
    • I cracked Samsung | SR...
    Company Tags:
    Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
    Timestamp:
    0:00 - Introduction
    #ShashwatTiwari #coding​​ #problemsolving​

Комментарии • 27

  • @kumaraniket1640
    @kumaraniket1640 13 дней назад +7

    To be very honeest very well and pin point explanation

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 12 дней назад +2

    Thanks 😊

  • @adityamittal8697
    @adityamittal8697 12 дней назад +1

    very nice and neat explaination , thank you buddy 👍👍

  • @OnstreamGaming
    @OnstreamGaming 12 дней назад +1

    Beautiful explanation , i always look into your solution and become able to write code on my own ,

  • @motivationalquotes6581
    @motivationalquotes6581 12 дней назад

    kal channel mila aur aaj se daily problem solving continue pura month solve karunga

  • @_phonesense
    @_phonesense 13 дней назад +2

    You explains really well bhaiya.

  • @POOJASINGH-bk8hg
    @POOJASINGH-bk8hg 12 дней назад +1

    Super easy solution, Thanks

  • @subhankarkanrar9494
    @subhankarkanrar9494 12 дней назад +1

    Very good explanation. Ek bachhe ko bhi samajh aa jayega Aisa explanation. ❤

  • @aggarwalsachin4854
    @aggarwalsachin4854 12 дней назад +1

    brilliant logic!!

  • @techwech8265
    @techwech8265 12 дней назад +2

    Yrr Awesome explanation brother always waiting for your video even after solving the problem by own ❤

  • @user-oi5oy6mq2y
    @user-oi5oy6mq2y 13 дней назад +1

    hats off for this explanation!!

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo 12 дней назад +2

    please continue this series love from canada🥰

  • @MohammedHasmi577
    @MohammedHasmi577 12 дней назад +1

    Amazing explanation sir

  • @user-oi5ls4rs5g
    @user-oi5ls4rs5g 13 дней назад +1

    good explain sir

  • @mr.nishantawasthi4402
    @mr.nishantawasthi4402 13 дней назад +1

    Osm explain sir

  • @deluluvish
    @deluluvish 13 дней назад +5

    class Solution {
    public int minDifference(int[] nums) {
    int n = nums.length; // Step 1: Get the length of the array.

    if (n

  • @aggarwalsachin4854
    @aggarwalsachin4854 12 дней назад +1

    3:10 🤣🤣🤣

  • @AnkushPundir-hh2sn
    @AnkushPundir-hh2sn 12 дней назад +1

    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));
    }
    }

  • @adarshjain3058
    @adarshjain3058 12 дней назад +1

    dudee...plzz plz plzzzz roz ke dcc ke solutions dalna shuru kar do yaarr/...bahout sexy explanation mann

  • @kamranwarsi12b22
    @kamranwarsi12b22 13 дней назад +1

    3:09 💀

  • @priyanshkumariitd
    @priyanshkumariitd 13 дней назад +1

    Bhaiya, please make a video on Leetcode 2035 problem. I'm stuck on this problem since 2 weeks.

  • @PrakashRai-ff3pr
    @PrakashRai-ff3pr 13 дней назад +1

    so after sorting we only need to change the element size by there next value??

  • @Pratikk_Rathod
    @Pratikk_Rathod 12 дней назад

    Noise

  • @VivekSingh-bx6ig
    @VivekSingh-bx6ig 12 дней назад +1

    How to prove that there are only 4 cases ?

    • @AkashRoy-do2dg
      @AkashRoy-do2dg 12 дней назад

      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.