p0uya3767's blog

By p0uya3767, history, 4 months ago, In English

Two pointers is a very simple and useful algorithm and actually using it is optional but, using it will make your algorithm easier and more simple.

but now, how to use it ? I think its good for you to look at https://www.geeksforgeeks.org/two-pointers-technique/ too. it'll be useful:blush:

so let go ...

As it's shown by its name this algorithm use two pointers on an array(or two arrays) which initially are located at position x, y . then if CONDITION1 move pointer1 one to left/right and if CONDITION2 move pointer2 one to left or right.

now let's switch to code.

QUESTION ANSWER SPOIL DANGER ================== to help you understand more I'll use one easy question and analyze them together.

QUESTION 1:( 1968B - Prefiquence )

so it says that we have two binary strings a,_ b_ and we want to find the maximum number of k which is the first k consecutive elements of a that are subsequence of b.

so what we do is we initially locate p1 (first pointer) at first of a and p2 (second pointer) at first of b.

if a[p1] == b[p2] : p1 ++
p2 ++

now p1 is the number of k.:sunglasses:

answer

this are some more easy questions that may help you: 1873D - 1D Eraser 1972A - Contest Proposal 1851B - Parity Sort

I hope you enjoyed reading this article.:blush: MAY THE CODE BE WITH YOU!:pray:

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 months ago, # |
  Vote: I like it +1 Vote: I do not like it

basi mozakhraf bood.sepas

dostdaranat va hamkelasihae azizat kianmehr biglari va ali roueintan

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    basi sher nagooeed doostnadar chiz na yani doostdar va hamkelasi shoma pouya izadi