(Remade) Leetcode 605 - Can Place Flowers | Array

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

Komentáře • 13

  • @BadriBlitz
    @BadriBlitz Před 3 lety +1

    Nice explanation.

  • @NideeshTerapalli
    @NideeshTerapalli  Před rokem

    Hey there! Just wanted to let you know that some of the links in this comment are affiliate links, which means that if you make a purchase through them, I may earn a small commission. Don't worry though, it doesn't cost you anything extra and it helps support this channel so I can continue to make more videos for you. Thank you so much for your support, and as always, all opinions are my own!
    Start getting great at system design: bytebytego.com?fpr=nideesh (affiliate link)
    Handpicked Algorithms and Data Structures for Interview To Save Time: interviewpen.com/?via=nideesh (affiliate link)
    Fast track to becoming a knowledgeable SWE www.educative.io/unlimited?aff=K1z6 (affiliate link)

  • @SudhanshuKumar-jl8iw
    @SudhanshuKumar-jl8iw Před 4 lety +4

    In the if block we should check for last i.e i==k-1 instead i ==n-1

  • @RajatSingh-dg8ov
    @RajatSingh-dg8ov Před 3 lety

    Dude, I saw you on gfg video explaining palindromic string subset and here!. Please make more videos!. Your explanation is soo good.

  • @ankitapandey8655
    @ankitapandey8655 Před 3 lety

    There should be "k" in the if statement , third part i.e i == k-1 || arr[i +1] ==0 , otherwise it will give wrong answer for boundary condition

  • @DeepakLaxkar147
    @DeepakLaxkar147 Před 3 lety

    Nice and simple explanation. Thanks

  • @0anant0
    @0anant0 Před 4 lety

    Very nice explanation and combining of boundary conditions. Since we place a flower at i only when right (i+1) is empty, we can incr i while doing a[i] = 1 (to skip the right empty slot) ==> change to a[i++] = 1.
    Also, acc to convention, we could have used n for array len and k for num of flowers.

  • @MichaelSalo
    @MichaelSalo Před 3 lety +1

    Are you sure we want to mutate the input array?

  • @edwardteach2
    @edwardteach2 Před 3 lety

    Python solution:
    class Solution(object):
    def canPlaceFlowers(self, flowerbed, n):
    """
    :type flowerbed: List[int]
    :type n: int
    :rtype: bool
    """
    count = 0
    for i in range(0,len(flowerbed)):
    if flowerbed[i] == 0 and ( i == 0 or flowerbed[i-1] == 0) and ( i == len(flowerbed) - 1 or flowerbed[i+1] == 0):
    flowerbed[i] = 1
    count += 1

    return count >= n
    Runtime: 168 ms, faster than 19.37% of Python online submissions for Can Place Flowers.
    Memory Usage: 14.2 MB, less than 29.55% of Python online submissions for Can Place Flowers.

  • @prayasjain9185
    @prayasjain9185 Před 3 lety

    we don't need to use a new count variable, we can decrement the N each time when we plot a new flower.
    and return n

  • @demidrek-heyward
    @demidrek-heyward Před 4 lety

    thanks!

  • @vishnugajulapalli5305
    @vishnugajulapalli5305 Před 3 lety

    Bro, are u from Telugu states?