from typing import List


class Solution:
    def binary_search(self, array, x, low, high):
        if high >= low:
            mid = low + (high - low) // 2
            if array[mid] == x:
                return mid, None, None
            elif array[mid] > x:
                return self.binary_search(array, x, low, mid - 1)
            else:
                return self.binary_search(array, x, mid + 1, high)
        else:
            return None, high, low

    def searchInsert(self, nums: List[int], target: int) -> int:
        if len(nums) == 1:
            return 1 if target > nums[0] else 0
        bingo, high, low = self.binary_search(nums, target, 0, len(nums) - 1)
        print(f"b: {bingo}")
        print(f"h: {high}")
        print(f"l: {low}")
        if bingo or bingo == 0:
            return bingo
        else:
            return low


sl1 = Solution()
print(sl1.searchInsert([1, 3, 5, 6], target=5))
print("---")
print(sl1.searchInsert([1, 3, 5, 6], target=2))
print("---")
print(sl1.searchInsert([1, 3, 5, 6], target=7))
print("---")
print(sl1.searchInsert([1, 3], target=1))
print("---")
print(sl1.searchInsert([1], target=0))
print("---")
print(sl1.searchInsert([1], target=1))
