Max Chunks To Make Sorted | Leetcode 769

Поделиться
HTML-код
  • Опубликовано: 21 дек 2024

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

  • @umeshkaushik710
    @umeshkaushik710 3 дня назад +1

    00:08 Understanding the Max Chunks To Make Sorted problem on LeetCode.
    02:09 Understanding partitioning for sorting in Leetcode 769.
    04:09 Determining valid partition points in a sorted array.
    06:16 Understanding partition points for sorting permutations.
    08:17 Maximize partitions based on anagram groups effectively.
    10:17 Partitioning an array requires max left to be less than min right.
    12:24 Understanding block creation for array partitioning based on maximum values.
    14:26 Creating partitions by tracking maximum values in the array.
    16:23 Counting anagrams through an efficient linear time approach.

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo 2 дня назад

    Thank you teacher, your explaination is very excellent to approach!

  • @bharat_india12
    @bharat_india12 2 дня назад

    class Solution {
    public:
    int maxChunksToSorted(vector& arr) {
    int chunk=0;
    int sum1=0,sum2=0;
    int i=0;
    for(auto x:arr){
    sum1+=i;
    sum2+=x;
    if(sum1==sum2){
    chunk++;
    }
    i++;
    }
    return chunk;

    }
    };

  • @nitian__himanshu3570
    @nitian__himanshu3570 2 дня назад

    Thank you sir !!!!!!!!!!!!!!!!!!!!!!!!!!
    Understood 100%

  • @ayushdubey5003
    @ayushdubey5003 2 дня назад +1

    thanks sir 🤗
    small request can you please provide a small post or a code block in which we can refer the brute force approach just to the understand in more depth about the solution ....

    • @techdose4u
      @techdose4u  2 дня назад

      that would be too much for me 🥵
      You can try and share your issue if you get

  • @rohanp7051
    @rohanp7051 2 дня назад

    Another intuitive approach is to compare the prefix sums of the given array and the fully sorted array at each index. If they are the same, it means a new chunk can be created.

  • @sailendrachettri8521
    @sailendrachettri8521 2 дня назад

    Thank you sir :)

  • @beinghappy9223
    @beinghappy9223 2 дня назад

    Excellent explanation

  • @manishgupta8057
    @manishgupta8057 2 дня назад

    I really liked this video❤

  • @eprithvikushwah4754
    @eprithvikushwah4754 3 дня назад +2

    Using max-heap
    class Solution {
    public:
    int maxChunksToSorted(vector& arr) {
    int ans = 0 ;
    int val = 0;
    priority_queue pq;
    for(int i= 0 ; i < arr.size(); i++){
    pq.push(arr[i]);
    if(!pq.empty() && val==pq.top()){
    ans++;
    while(pq.empty()) pq.pop();
    }
    val++;
    }
    return ans;
    }
    };