Skip to content

Missing Test Case in for find-target-in-rotated-sorted-array #5968

Description

@AadishJ

Bug Report for https://neetcode.io/problems/find-target-in-rotated-sorted-array

So i submiited this code

public:
    int search(vector<int>& nums, int target) {
        int min = findMin(nums);
        int low=0,high=min,mid=0;
        while(low<=high){
            mid = low + (high-low)/2;
            if(nums[mid]>target){
                high=mid-1;
            }else if(nums[mid]<target){
                low=mid+1;
            }else{
                return mid;
            }
        }
        low=min,high=nums.size()-1,mid=0;
        while(low<=high){
            mid = low + (high-low)/2;
            if(nums[mid]>target){
                high=mid-1;
            }else if(nums[mid]<target){
                low=mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
    int findMin(vector<int> &nums) {
        int low =0,high=nums.size()-1,mid=0;
        if(nums[low]<nums[high]) return nums[low];
        while(low<=high){
            mid = low + (high-low)/2;
            if(nums[low]>nums[high] && nums[mid]>nums[low]){
                low=mid;
            }else if(nums[low]>nums[high] && nums[mid]<nums[low]){
                high=mid;
            }else{
                return high;
            }
        }   
        return -1;
    }
};

this did pass all the test case and got accepted but it should have failed
the failed test case is:
array=[100,200]
target = 200
the wrong line is this
if(nums[low]<nums[high]) return nums[low];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions