def find_missing_number(nums: list[int]) -> int:
    """

    Complexity:
        N = len(nums)
            Time: O(N) (iterate the entire array)
            Space: O(1) (in-place computations)

    Args:
        nums: array containing n distinct numbers
              taken from the range [0,n]
              (n+1 possible numbers)

    Returns: the missing number in the range [0,n]

    Examples:
        >>> find_missing_number([])
        0
        >>> find_missing_number([0])
        1
        >>> find_missing_number([1])
        0
        >>> find_missing_number([4, 0, 3, 1])
        2
        >>> find_missing_number([8, 3, 5, 2, 4, 6, 0, 1])
        7

    """
    """ALGORITHM"""

    def swap_elements(i, j):
        nums[i], nums[j] = nums[j], nums[i]

    ## INITIALIZE VARS ##
    curr_idx, n = 0, len(nums)

    ## CYCLIC SORT ## O(n)
    while curr_idx < n:
        target_idx = nums[curr_idx]
        if curr_idx != target_idx and target_idx < n:
            swap_elements(curr_idx, target_idx)
        else:
            curr_idx += 1

    ## FIND item ## O(n)
    for curr_idx in range(n):
        target_idx = nums[curr_idx]
        if curr_idx != target_idx:
            return curr_idx
    else:
        return n