title: Given a string, find two identical subsequences with consecutive indexes C++
body: <p>I need to construct an algorithm (not necessarily effective) that given a string finds and prints two identical subsequences (by print I mean color for example). What more, the union of the sets of indexes of these two subsequences has to be a set of consecutive natural numbers (a full segment of integers).</p>
  
  <p>In mathematics, the thing what I am looking for is called "tight twins", if it helps anything. (E.g., see the <a href="https://www.google.com/search?q=avoiding+tight+twins+in+sequences&amp;btnl" rel="noreferrer">paper (PDF) here</a>.)</p>
  
  <p>Let me give a few examples:</p>
  
  <p>1) consider string 231213231</p>
  
  <p>It has two subsequences I am looking for in the form of "123". To see it better look at this image:</p>
  
  <p><a href="https://i.stack.imgur.com/QAdTN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QAdTN.png" alt="231213231"></a></p>
  
  <p>The first subsequence is marked with underlines and the second with overlines. As you can see they have all the properties I need.</p>
  
  <p>2) consider string 12341234</p>
  
  <p><a href="https://i.stack.imgur.com/7P7ad.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7P7ad.png" alt="12341234"></a> </p>
  
  <p>3) consider string 12132344.</p>
  
  <p>Now it gets more complicated:</p>
  
  <p><a href="https://i.stack.imgur.com/QL9s6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QL9s6.png" alt="enter image description here"></a></p>
  
  <p>4) consider string: 13412342</p>
  
  <p>It is also not that easy:</p>
  
  <p><a href="https://i.stack.imgur.com/48nAe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/48nAe.png" alt="enter image description here"></a></p>
  
  <p>I think that these examples explain well enough what I meant.</p>
  
  <p>I've been thinking a long time about an algorithm that could do that but without success. </p>
  
  <p>For coloring, I wanted to use this piece of code:</p>
  
  <pre><code> using namespace std;
  HANDLE  hConsole;
          hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(hConsole, k);
  </code></pre>
  
  <p>where k is color.</p>
  
  <p>Any help, even hints, would be highly appreciated.</p>