Leetcode 3355 | Zero Array Transformation I | Weekly Contest 424

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

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

  • @diannic188
    @diannic188 3 дня назад

    Hi, there!
    Thank you for the explanation, but in the first example nums = [1, 0, 0] and queries = [[0,2]] it's not clear for me why we're not modifying the number zero. Could you please explain this?
    Thanks a lot!

    • @dThapa966
      @dThapa966 3 дня назад

      Because at the end, we are looking for our array to be all 0's example - [0,0,0,0] at the end. If you decrement more than 0, you'll get a negative number. So subtracting further after seeing a 0 will ruin the array.

    • @RoadToFAANG1992
      @RoadToFAANG1992  3 дня назад

      What @dThapa966 said is correct. We want to make all the elements equal 0. For each query, we only need to choose a subset of elements in the range. This means that we can choose not to decrement any elements which are already 0