code: public static short countCommon(short[] indices1, short[] indices2) {
          short numCommonIndices = 0;
          int i = 0;
          int j = 0;
          while (i < indices1.length && j < indices2.length) {
              if (indices1[i] < indices2[j]) {
                  i++;
              } else if (indices2[j] < indices1[i]) {
                  j++;
              } else {
                  numCommonIndices++;
                  // Equal indices.
                  i++;
                  j++;
              }
          }
          for (; i < indices1.length; i++) {
              numCommonIndices++;
          }
          for (; j < indices2.length; j++) {
              numCommonIndices++;
          }
          return numCommonIndices;
      }
docs: Counts the number of indices that appear in both arrays.
  
  @param indices1 Sorted array of indices.
  @param indices2 Sorted array of indices.