Two Pointers

Needs to be ordered

  • Outer-layer deduplication (on i): Skip repeated starting values so each distinct number is used only once as the first element.
  • Inner-layer deduplication (on l and r): After finding a triplet, skip repeated values at the left and right pointers so each triplet is produced only once.

Check the condition between one window
Don’t need to be ordered

  • vector<int> last(256,-1) records the last position of a character, 255 characters max
  • last[c] >= l as c has to be within the [l,r]

Leave a Reply

Discover more from Daily Learning

Subscribe now to keep reading and get access to the full archive.

Continue reading