I've solved a lot of two pointers problems, I found that every problem I solved with two pointers is also solvable with binary search, is that true?

# | User | Rating |
---|---|---|

1 | tourist | 3805 |

2 | maroonrk | 3637 |

3 | Benq | 3513 |

4 | ecnerwala | 3506 |

5 | MiracleFaFa | 3466 |

6 | slime | 3428 |

7 | jiangly | 3415 |

8 | Radewoosh | 3399 |

9 | greenheadstrange | 3393 |

10 | djq_cpp | 3391 |

# | User | Contrib. |
---|---|---|

1 | awoo | 192 |

2 | -is-this-fft- | 191 |

3 | Monogon | 185 |

4 | Um_nik | 182 |

4 | YouKn0wWho | 182 |

6 | maroonrk | 170 |

7 | antontrygubO_o | 167 |

8 | errorgorn | 166 |

8 | kostka | 166 |

10 | SecondThread | 165 |

I've solved a lot of two pointers problems, I found that every problem I solved with two pointers is also solvable with binary search, is that true?

↑

↓

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/17/2022 11:20:31 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Two pointers is a very generic technique, and I am sure there are problems you can solve using two pointers but not binary search. For example, Mo's algorithm is in some sense an application of two pointers, but I don't see how someone could use binary search in it.

It isn't true, but the answer to that question isnt really thst important. Sets for example can solve everything a priority queue can, but people still use priority queues for a lot of problems.

Sometimes using binary search goes over the time limit, sometimes you would need an extra structure to use binary search, sometimes two pointers is more convinient to code.

Learn both and use them when necessary (even though i would say that binary search is more important)

no because when using two pointers when you add one to one of the pointers only one element changes

What's your binary search alternative to Manacher's Algorithm for finding the longest palindromic substring?

Forward and backward string hashes and binary search for longest length which they are equal at every position. Easier than Manacher's and also easily linear time if you just don't binary search and rather do a sliding window that you expand when possible at the cost of having some probability of failure

Most of them, because binary search is also application of two pointers, i also used two pointers, l and r

I wonder how you so accurately predicted what is going on in yesterday’s problem C.