def counting(elements, k):
    """Counting Sort Algorithm

    Fill an array with the number of times that a number appears in given elements
    Traverse the array and fill up a new one with the same length, for every element
    different from 0 move its value to the new array, decrement the value by one and
    continue until 0

    Parameters
    elements: List of elements to be sorted
    k: Maximum range of values of our elements

    Returns:
    list of sorted elements
    """
    aux = [0] * (k+1)

    #load the accounting of all elements
    for e in elements:
        aux[e] += 1

    new_aux = [0] * len(elements)
    i = 0
    #traverse aux array
    for j in range(len(aux)):
        while aux[j] > 0:
            #if we have some element here
            #move its index to the new array
            new_aux[i] = j
            i+=1 #this will keep new_aux moving
            aux[j] -= 1
            #decrement aux[j] in order to move the correct
            #amount to new_aux

    return new_aux