```ts
/**
 * Finds the first and last occurrence of the target in a sorted array.
 * Uses binary search to achieve O(log n) time complexity.
 * Returns [-1, -1] if the target is not found.
 */
export function searchRange(nums: number[], target: number): [number, number] {
    if (!nums || nums.length === 0) {
        return [-1, -1];
    }

    // Find the first occurrence (leftmost index)
    const findFirst = (): number => {
        let left = 0;
        let right = nums.length - 1;
        let result = -1;

        while (left <= right) {
            const mid = Math.floor((left + right) / 2);

            if (nums[mid] === target) {
                result = mid;
                right = mid - 1; // Continue searching to the left
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }

        return result;
    };

    // Find the last occurrence (rightmost index)
    const findLast = (): number => {
        let left = 0;
        let right = nums.length - 1;
        let result = -1;

        while (left <= right) {
            const mid = Math.floor((left + right) / 2);

            if (nums[mid] === target) {
                result = mid;
                left = mid + 1; // Continue searching to the right
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }

        return result;
    };

    const first = findFirst();
    
    // If target is not found, no need to search for last occurrence
    if (first === -1) {
        return [-1, -1];
    }

    const last = findLast();
    return [first, last];
}
```