Update appNew update is available. Click here to update.
About
Daffodil International University 2024
My Stats
EXP gained
yellow-spark
3623
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
0
Know more
174
Total problems solved
164
Easy
10
Moderate
0
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

4 days

Less

More

Achievements
1
Sensei
Guided path
Fundamentals of Html
Discussions
99.97% better performance in O(log(n)) time complexity in C++
Interview problems
int firstOcc(vector<int>&arr,int n, int x){
	int low=0, high=n-1;
	int mid;
    while (low <= high) {
		mid=(low+high)/2;
		if((mid==0 && arr[mid]==x) || (arr[mid]==x && arr[mid-1]<x)){
			return mid;
		}
		else if(x>arr[mid]){
			low=mid+1;
		}
		else{
			high=mid-1;
		}
    }
	return -1;
}
int lastOcc(vector<int>&arr, int n, int x){
	int low=0, high=n-1;
	int mid;
	while(low<=high){
		mid=(low+high)/2;
		if((mid==n-1 && arr[mid]==x) || (arr[mid]==x && arr[mid+1]>x)){
			return mid;
		}
		else if(x<arr[mid]){
			high=mid-1;
		}
		else{
			low=mid+1;
		}
	}
	return -1;
}
pair<int, int> findFirstLastPosition(vector<int> &arr, int n, int x)
{
	pair<int,int>pr;
	pr.first=firstOcc(arr,n,x);
	pr.second=lastOcc(arr,n,x);
	return pr;
}
profile
tazbid
Published On 03-Apr-2023
220 views
0 replies
0 upvotes