LeetCode 1552 - Magnetic Force Between Two Balls - Java

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • Solution, explanation, and complexity analysis for LeetCode 1552 in Java
    Problem Description:
    leetcode.com/p...
    Code:
    github.com/Ana...

КОМЕНТАРІ • 6

  • @rostyslavmochulskyi159
    @rostyslavmochulskyi159 3 місяці тому +1

    In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(logn) for sorting

    • @Alpha-Code
      @Alpha-Code  3 місяці тому +1

      Gotcha, I think in Python its also not O(1) for sort but most people write it that way.

  • @MehdiKhfifi
    @MehdiKhfifi 3 місяці тому +2

    i don't understand why the left position has to be 1 and not 0?

    • @tzuilee588
      @tzuilee588 3 місяці тому

      it doesn't matter if it's 0 or 1, we are binary searching the gap not the array index

    • @Alpha-Code
      @Alpha-Code  3 місяці тому +1

      It wouldn't matter, but also if you have enough buckets to put the balls in if it was zero you'd put every ball in the same bucket which wouldn't make sense. You can always put the balls in different buckets and the minimum space between buckets is 1.

  • @margin100px
    @margin100px 3 місяці тому

    Cool thumbnail!!