function fillEmptyClusters(distances, minCount = 1) {
  return tf.tidy(() => {
    const nClusters = distances.shape[0];
    // mins: the IDs of centroid that's nearest to each data instance, shape = [nInscances]
    let mins = tf.argMin(distances, 0).toInt();
    let mutatedIds = tf.tensor([]);
    let count = 0;

    while (count < nClusters) {
      const clusterSampleCount = tf.sum(tf.oneHot(mins, nClusters), 0);
      const nEmptyClusters = tf.sum(
        tf.less(clusterSampleCount, tf.scalar(minCount)),
        0
      );
      // nEmptyClusters is a scalar, but `.dataSync()` returns an array with length = 1
      if (nEmptyClusters.dataSync()[0] <= 0) {
        return mins;
      }
      // tackle clusters one by one, starting from the smallest cluster
      const clusterToFill = tf.argMin(clusterSampleCount, 0).toInt();
      // dataIds that have already been mutated before should not be mutated again
      // set values at these indices to Infinity so they will not be picked by `argmin`
      const maskedDistances = assign(
        // only care about distances to the centroid of `clusterToFill`
        tf.squeeze(tf.gather(distances, clusterToFill)),
        mutatedIds,
        tf.scalar(Infinity)
      );

      // assign cluster K to data point P if P has shortest distance (among previously un-mutated data) to cluster K's center
      const dataIdToMutate = tf.argMin(maskedDistances, 0).reshape([1]);
      mutatedIds = tf.concat([mutatedIds, dataIdToMutate]);
      mins = assign(mins, dataIdToMutate, clusterToFill.reshape([1]));
      count++;
    }
    return mins;
  });
}
check whether nearest include all possible cluster Ids
(i.e.all clusters have non - zero number of instances)
if not, assign the one with farthest distance from center to the missing cluster
@param {Tensor2D} distances - distances between data instances and centroids, shape = [nClusters, nInscances]
@param {Number} minCount - minimum number of instances in a cluster
@returns {Tensor1D} indices of the nearest centroid to each data instance
(after empty clusters are filled), shape = [nInscances]
e.g. consider clustering a dataset with 4 data points into 3 clusters:
```
distances = [
  [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9, 10, 11, 12]
],
```
Before filling empty clusters, cluster assignment of all 4 data instances will be `0`,
since for all 4 data instances, centroid_0 is the nearest to them among the 3 centroids:
```
mins = [0, 0, 0, 0]
```
However we need to ensure cluster_1 and cluster_2 also have at least 1 data instance in them.
First for cluster_1, we mutate the cluster assignment of instance_0 from `0` to `1`,
because distnace between instances_0 and centroid_1 is `5`, smallest among all data instances:
```
mins = [1, 0, 0, 0]
```
Then for cluster_2, we mutate the cluster assignment of instance_1 from `0` to `2`,
because distnace between instances_1 and centroid_2 is `10`, smallest among
all data instances except for instances_0 (which has already been mutated in previous round):
```
mins = [1, 2, 0, 0]
```