title: Policemen Catch Thieves
signature: function policemenCatchThieves($arr, $n, $k) {
source_py: def policemen_catch_thieves(arr, n, k):
      i = 0
      l = 0
      r = 0
      res = 0
      thi = []
      pol = []
      while (i < n):
          if (arr[i] == 'P'):
              pol.append(i)
          elif (arr[i] == 'T'):
              thi.append(i)
          i += 1
      while ((l < len(thi)) and (r < len(pol))):
          if (abs((thi[l] - pol[r])) <= k):
              res += 1
              l += 1
              r += 1
          elif (thi[l] < pol[r]):
              l += 1
          else:
              r += 1
      return res
source_cpp: int policemen_catch_thieves(vector<char> arr, int n, int k) {
    int res = 0;
    vector < int > thi;
    vector < int > pol;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] == 'P' ) pol . push_back ( i );
      else if ( arr [ i ] == 'T' ) thi . push_back ( i );
    }
    int l = 0, r = 0;
    while ( l < thi . size ( ) && r < pol . size ( ) ) {
      if ( abs ( thi [ l ] - pol [ r ] ) <= k ) {
        res ++;
        l ++;
        r ++;
      }
      else if ( thi [ l ] < pol [ r ] ) l ++;
      else r ++;
    }
    return res;
  }