Oracle Interview 8th March 2025

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-03-08Added By Anonymous
Source: Link

Company: Oracle
Role: ic-1, ic-2
Interview Stage: Phone Screen
Location: unknown
Year: 2025

Original Post Content:

What's wrong in this solution? Interviewer didn't accept it for higher values? I guess the lower bound and upper bound are actually calculated like this only.

    def searchRange(self, nums: List[int], target: int) -> List[int]:
        n = len(nums)
        def lower_bound():
            low, high = 0,n-1
            ans = n
            while low<=high:
                mid = (low+high)//2
                if nums[mid]>=target:
                    ans = mid
                    high = mid-1
                else:
                    low = mid +1
            return ans

        def upper_bound():
            low, high = 0,n-1
            ans = n
            while low<=high:
                mid = (low+high)//2
                if nums[mid]>target:
                    ans = mid
                    high = mid-1
                else:
                    low = mid +1
            return ans
        if target not in nums: return [-1,-1]
        return [lower_bound(), upper_bound()-1]
Comments