from typing import Counter


def fill_histogram(histograms, indices, hist_idx, normalize=True):
    """
    Compute a histogram and fill in the designated entry in the array histograms.

    :param histograms: Array that will contains histograms.
    :param indices: Array with values from which a histogram should be computed.
    :param hist_idx: Index of row that will get filled in in histograms.
    :param normalize: Whether to normalize the histogram.
    :return: histograms: The array containing histograms with row "hist_idx" filled in by creating a histogram from the
                         entries in "indices".
    """
    counts = Counter(indices)
    for key in counts:
        histograms[hist_idx, key] += counts[key]
    rowsum = sum(histograms[hist_idx, :])
    if rowsum != 0 and normalize is True:
        histograms[hist_idx, :] /= rowsum

    return histograms