Please read the new rule regarding the restriction on the use of AI tools. ×

viraj777's blog

By viraj777, history, 2 years ago, In English

One mandatory requirement to apply binary search is our searching space should be in sorted range . Otherwise there is no meaning of this algorithm.

One type of question in that given array or any data structure is in sorted manner or we have to sort it , But in sort searching space is given , in this only one function will be needed

Second and most famous method is in that we have to make our own search space, our answer will be lie in that range , so in that range apply binary search , check that whether this answer satisfied conditions or not , Now if condition satisfied , then there two choice to go left or right , this depends on que , If it asks for minimum then go for left and otherwise go for right side .

You can find this type of pattern in leetcode , here I have attached one codeforces link of this type question :

https://codeforces.me/problemset/problem/1119/B https://codeforces.me/problemset/problem/279/B

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it