<gouthampradhan>two_pointers_SubarraysWithKDifferentIntegers_1.java
private int calculate(int[] A, int K) {
    int count = 0;
    int[] frequency = new int[A.length + 1];
    int currCount = 0;
    for (int i = 0, j = 0; i < A.length; i++) {
      frequency[A[i]]++;
      if (frequency[A[i]] == 1) {
        currCount++;
      }
      while (currCount > K) {
        frequency[A[j]]--;
        if (frequency[A[j]] == 0) {
          currCount--;
        }
        j++;
      }
      count += (i - j + 1);
    }
    return count;
  }
private int sample_funcname ( int [ ] var_0 , int var_1 ) {
  int var_3 = 0 ;
  int [ ] var_6 = new int [ var_0 . length + 1 ] ;
  int var_7 = 0 ;
  for ( int var_8 = 0 , var_9 = 0 ;
  var_8 < var_0 . length ;
  var_8 ++ ) {
    var_6 [ var_0 [ var_8 ] ] ++ ;
    if ( var_6 [ var_0 [ var_8 ] ] == 1 ) {
      var_7 ++ ;
    }
    while ( var_7 > var_1 ) {
      var_6 [ var_0 [ var_9 ] ] -- ;
      if ( var_6 [ var_0 [ var_9 ] ] == 0 ) {
        var_7 -- ;
      }
      var_9 ++ ;
    }
    var_3 += ( var_8 - var_9 + 1 ) ;
  }
  return var_3 ;
}
