LeetCode 2055. Plates Between Candles - O(n + q)

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

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

  • @nahyanmunawar9977
    @nahyanmunawar9977 Год назад +7

    this is the best video to understand this problem even if you're using python

  • @rushio8673
    @rushio8673 2 месяца назад

    loved it, one of the easiest and best explanation. Thank you !

  • @web-unlocked
    @web-unlocked 3 месяца назад

    Love you solution (and your voice)

  • @homeroserna9983
    @homeroserna9983 8 месяцев назад +1

    Good solution. I like that you did it with regular arrays makes it easy to transfer the logic to other languages.

  • @saunvid6721
    @saunvid6721 2 года назад +4

    Great solution thanks man

  • @ShichaoCheng
    @ShichaoCheng Год назад +1

    That is a great clear explanation. Thanks!

  • @mayankbhanot8986
    @mayankbhanot8986 4 месяца назад

    omg, the prefix sum explanation was so good

  • @aaditya_87
    @aaditya_87 9 месяцев назад +1

    awesome!

  • @fredyrocky
    @fredyrocky 6 месяцев назад

    How about using two pointers. The first pointer starts from the beginning of each range and increases by 1 until it finds the first pipe and is less than end of range. The second pointer if (left pointer +1) and increases by 1 until it finds a pipe. We add the difference between both the pointers -1 as the current count of the stars. Then, we make the first pointer to start from the second pointer. And the secondpointer starts from firstpointer +1. We always check if the pointers are less than right.

  • @ZachDift-kc4nk
    @ZachDift-kc4nk 3 месяца назад

    I got this question for amazon's OA and also a question similar to this for IBM's OA on the coding portion so this is a good question to review. Too bad i didnt know how to do it 😭

  • @santiagoramirez851
    @santiagoramirez851 5 месяцев назад

    Awesome!

  • @spacetoast7783
    @spacetoast7783 Год назад

    Another option would be to construct the running totals, and then use a binary search to find the rising edges.

  • @MC-qj2zd
    @MC-qj2zd 2 года назад

    I do this in javascript but dont get that fast of a result

  • @AdpYTExplorer
    @AdpYTExplorer Год назад

    isn't using treeset better since O(logn) is faster than O(n) ?

    • @spacetoast7783
      @spacetoast7783 Год назад

      You have to iterate over the array anyhow, so it doesn't matter for time complexity, but yeah it probably would be better in practice.

    • @louiso1477
      @louiso1477 2 месяца назад

      accessing the nearest candle is o(1) with an array, but o(logn) for a treeset. initialising either is o(n)