fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int smallest(int a[],int l,int r)
  5. {
  6. if(l>r)
  7. return r+1;
  8. if(l!=a[l])
  9. return l;
  10.  
  11. int mid=l+(r-l)/2;
  12.  
  13. if(a[mid]<mid)
  14. return smallest(a,l,mid);
  15. else
  16. return smallest(a,mid+1,r);
  17. }
  18.  
  19. int main() {
  20. // your code goes here
  21. int a[]={0,1,2,3,4};
  22. cout<<smallest(a,0,4);
  23.  
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
5