Find First and Last Position - Implementation

Here is the implementation:

function searchRange(nums, target):
    left = lowerBound(nums, target)

    if left == nums.length or nums[left] != target:
        return [-1, -1]

    right = lowerBound(nums, target + 1) - 1
    return [left, right]

function lowerBound(nums, target):
    left = 0
    right = nums.length

    while left < right:
        mid = (left + right) / 2
        if nums[mid] < target:
            left = mid + 1
        else:
            right = mid

    return left

Two binary searches: O(logn)O(\log n) time, O(1)O(1) space (excluding input).