Max Chunks To Make Sorted | 3 Approaches | Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

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

  • @touhidiutcse
    @touhidiutcse 12 วันที่ผ่านมา

    Excellent explanation, I greatly appreciate for covering all of the 3 approaches!
    If I am not mistaken:
    - Approach 1: applicable for arrays with duplicate numbers as well
    - Approach 2 & 3: applicable for arrays with unique number only

    • @ethostypos
      @ethostypos  12 วันที่ผ่านมา +1

      Yes. Because if duplicate elements are there, then the indices won't match with the sorted version of the array.

    • @touhidiutcse
      @touhidiutcse 12 วันที่ผ่านมา +1

      @@ethostypos Thank you, I also learned a 4th approach ma'am which is by using Stack!
      Stack = []
      Largest= 0
      for num in arr:
      Largest= num
      While Stack & Stack[-1] > num:
      Largest= max(Largest, Stack[-1])
      Stack.pop()
      Stack.append(Largest)
      Return len(Stack)

  • @newbie6449
    @newbie6449 12 วันที่ผ่านมา

    Gyanchakshu khul gaye 😮