3224. Minimum Array Changes to Make Differences Equal | Prefix Sums | Why not Greedy

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 34

  • @ARYANMITTAL
    @ARYANMITTAL  Před měsícem +12

    This is not a normal Medium Problem, it is Medium Hard (not in terms of implementation but a why on every step makes it Hard), skip dry run (that is longest section) ❤
    Do connect on Twitter☺ : x.com/aryan_mittal007

  • @satviksrinivas8764
    @satviksrinivas8764 Před 7 dny

    Thank you I learned so much from this video!

  • @krishpoptani7862
    @krishpoptani7862 Před měsícem +3

    I did it in contest with same approach

  • @InWonderland-z2l
    @InWonderland-z2l Před měsícem +1

    wooaaahh awesome!!
    i thought about a lot of ways to get greedy approach to work during the contest.. and you tackled all of them in this video!

  • @priyamvadashah4839
    @priyamvadashah4839 Před měsícem +1

    Your explanations are getting so better!

  • @IK-xk7ex
    @IK-xk7ex Před měsícem

    Excellent problem, it's clear now after explaining :)

  • @-RAJSINGH
    @-RAJSINGH Před měsícem +4

    Finding this too hard 😢😢

  • @Mandh-c7r
    @Mandh-c7r Před měsícem

    Your effort helps us a lot ..... Explained it awesomely......i guess you also did it with greedy first ...coz this was the first test case where greedy failed for me 😄

  • @literally_ankur
    @literally_ankur Před měsícem

    Crazy question

  • @asthajain2511
    @asthajain2511 Před měsícem +2

    Aryan Bhai >>>>

  • @Rajdweep
    @Rajdweep Před měsícem +1

    nicely explained bro, but i dont think this should be a medium qs, the prefix intuition was pretty hard man.

  • @priyapandey8951
    @priyapandey8951 Před měsícem

    Bhaiya, I tried this approach which was to take the abs difference of all pairs and add it to a max priority queue and according to which diff has greater frequency that queue would handle it and we would check for all the diff in the increasing order of their frequencies so that way lesser number of operations would be required. Now considering n/2 differences even in the worst case would make it nearly half the size of array that is the worst case when all pairs have different frequency and then checking minimum operations for them would make it nearly O(10^5 * 10^3) would be 10^8 in worst case and generally that is allowed but my solution is still giving TLE. Can you explain where I went wrong?
    class Solution {
    private:
    struct myComp {
    constexpr bool operator()(
    pair const& a,
    pair const& b)
    const noexcept
    {
    return a.second < b.second;
    }
    };
    public:
    int minChanges(vector& nums, int k) {
    unordered_map freq;
    priority_queue pq;
    int n=nums.size();
    int i=0,j=n-1;
    while(i

  • @akashsonar6332
    @akashsonar6332 Před měsícem

    Well explained 👏

  • @studyplanet4656
    @studyplanet4656 Před měsícem +1

    What would be the difficulty of this question on codeforces

  • @mohd.vaseem7410
    @mohd.vaseem7410 Před měsícem

    great explanation bro

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 Před měsícem

    thanks mittal saab

  • @SAURABHKUMAR-yo7er
    @SAURABHKUMAR-yo7er Před měsícem

    gawd lvl explanation 🔥🔥

  • @nikhilprakash729
    @nikhilprakash729 Před měsícem

    Great Explanation!!!!!

  • @23cash86
    @23cash86 Před měsícem

    Good one

  • @chaitanyaamajala2582
    @chaitanyaamajala2582 Před měsícem +1

    🙇

  • @kergeysarjakin5592
    @kergeysarjakin5592 Před měsícem +1

    Bheek Pro Max the title of first timeline 🤣

  • @monilcharola6873
    @monilcharola6873 Před měsícem

    I solved it in Greedy way
    Find the difference with max freq
    Find the number of replacement moves to make the above difference
    return min(ans, (n-2)/2);
    This is an accepted solution in O(N)

    • @kartikegandhi3153
      @kartikegandhi3153 Před měsícem

      It might have worked in contest but idts that it is the correct approach

    • @omkara477
      @omkara477 Před měsícem

      Can u explained how is it working for this test case :
      [1,1,1,1,0,0,0,5,4,3,19,17,16,15,15,15,19,19,19,19] ?

    • @aysheri8321
      @aysheri8321 Před měsícem

      what's the n-2/2

  • @saumyaagarwal7
    @saumyaagarwal7 Před měsícem

    bro why are you not checking ans for all values from 0 to k .. you are just checking difference that are already formed by pairs...
    because my difference value can be between 0 to k..

  • @fraserdab
    @fraserdab Před měsícem +1

    Liked

  • @prajitbanerjee8226
    @prajitbanerjee8226 Před měsícem

    bro can you tell if this problem was on codeforces what would be its approximate rating like 1600?

  • @MOHITRANA-to7rf
    @MOHITRANA-to7rf Před měsícem +1

    Hold on kr kr ke kuch smjh nahi aya

  • @priyanshupriyam174
    @priyanshupriyam174 Před měsícem

    Finally

  • @silverpoision
    @silverpoision Před 21 dnem

    Laut awo Aryan Bhai....