Lower Bound-STL

Sort by

recency

|

437 Discussions

|

  • + 0 comments
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
        int n;
        cin >> n;
    
        vector<int> sorted_array;
    
        while (n > 0)
        {
            int number;
            cin >> number;
            sorted_array.push_back(number);
            n--;
        }
    
        int q;
        cin >> q;
    
        while (q > 0)
        {
            int y;
            cin >> y;
    
            vector<int>::iterator low_bound = lower_bound(sorted_array.begin(), sorted_array.end(), y);
            int idx = (low_bound - sorted_array.begin()) + 1;
    
            if (*low_bound == y)
                cout << "Yes " << idx << endl;
            else
                cout << "No " << idx << endl;
    
            q--;
        }
    }
    
  • + 0 comments

    include

    include

    using namespace std;

    int main() { int n; cin>>n; vectorm; for(int i=0;i>temp; m.push_back(temp); } int q; cin>>q; for(int i=0;i>temp; vector::iterator it; it=lower_bound(m.begin(),m.end(),temp); if(*(it+1)==temp||*it==temp){ cout<<"Yes"<<" "<

  • + 0 comments

    Here is Lower Bound - STL problem solution in C++ - https://programmingoneonone.com/hackerrank-lower-bound-stl-solution-in-cpp.html

  • + 1 comment

    Hey guys..C++ solution

    int main() {

    long long n; cin>>n; vectora(n); for(long long i=0; i>a[i];

    long long q; cin>>q; for(int i=0; i>x;

    auto it=lower_bound(a.begin(),a.end(),x);
    long long index=it - a.begin();
    
    if(it!=a.end() && *it==x)
    {
        cout<<"Yes"<<" "<<index+1<<endl;
    }
    else 
    {
      cout<<"No"<<" "<<index+1<<endl;
    }
    

    }

    }
    
  • + 0 comments

    c++14

        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n =0;
        int x =0;
        vector<int>vek;
        cin>>n;
        while (n > 0) {
            cin>>x;
            vek.push_back(x);
            n--;
        }
        int q=0;
        cin>>q;
        while (q > 0) {
            int y =0;
            vector<int>::iterator it;
            cin>>y;
            it = lower_bound(vek.begin(),vek.end(), y);
            if (*it!=y) {
                cout<<"No "<<(it-vek.begin()+1)<<'\n';
            }else
            {cout<<"Yes "<<(it-vek.begin()+1)<<'\n';}
            q--;
        }