Ternay Search is a very cool upgrade/modification on Binary Search logic There are enough resources available on this topic my favorite resource is :-
This blog will include a different implementation of the approach which I found very cool
int l=1,r=mx;
while(r>=l){
int mid = (r+l)/2;
int m1 = check(mid);
int m2 = check(mid+1);
if(m1>=m2){
ans = updateAns(and,m1);
r=mid-1;
}
else{
l=mid+1;
ans = updateAns(and,m2);
}
}
It would make more sense if you study the concept and then solve these 2 problems these are fairly recent problems as well
Would love any input to improve this blog.








I have this implementation that I found really helpful:
you just have to implement the function $$$f$$$, that depends on the problem.
Yeah this is actual implementation of Terneray Search and how it should be used but the way I have implemented you can see it is more like Binary Search even complexity wise it would be O(log2n)
I just always found that implementation easier
But Yeah This is exactly how Ternary Search should be used Thanks for the Input man
hii, sorry but why eps = 5? why can't we do eps = 2 for integers? what's the edge case?
tbh, I didn't want to think when I was choosing it, so I just put a big eps.
i tried problem: Simple Skewness using eps = 2 and it passed. still i've seen many other submission using eps = 5 while some people use eps = 3.
Yeah since difference is the derivative, it’s a smart idea