Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include<bits/stdc++.h>
using namespace std;
int solve(int arr[],int n, int ele){
int ans=-1;
int ans = -1;
int low=0;
int high=n-1;
while(low<=high){
int mid=low+(high-low)/2;
if(ele==arr[mid]){
return ele;
}
else if(ele>arr[mid]){
ans=mid;
high=mid-1;
}
else{
low=mid+1;
}
else if(arr[mid] > ele){
ans = mid;
high = mid - 1;
}
else {
low = mid + 1;
}
}
if(ans == -1) return -1; // ceil does not exist (all elements smaller than ele)
return arr[ans];
}
int main(){
Expand Down