Question is preety simple( H-Index II). Where i am missing ? i used binary search.


  • 0
    V

    I used: ans = max(min(f(i),i)) for each i 1 to n

    int binarySearch(vector<int>& citations,int low,int high,int n){
    int mid = low+(high-low)/2;

        int a = getValue(mid,citations[mid],n);
        int b = getValue(mid+1,citations[mid+1],n);
        int c = getValue(mid-1,citations[mid-1],n);
        cout<<c<<" "<<a<<" "<<b<<endl;
        if(high==low) return getValue(low,citations[low],n);
        
        if(high-low==1){
            return max(getValue(low,citations[low],n),getValue(high,citations[high],n));
        }
        
        
        if(a>b && a>c) return a;
        else
        if(a>b && a<c) return binarySearch(citations,low,mid-1,n);
        else
        return binarySearch(citations,mid+1,high,n);
        
        
    }
    
    int getValue(int index,int citation,int n){
        
        return min(n-index,citation);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.