My housemate is highly sensitive, and I'm considering moving out. I wish the U.S. housing is more affordable…
I was too hungry. I'm thinking about increasing my calorie intake a bit for a few days.
It's embarassing, but I don't remember much about the counting sort, so I took some time to recall it.
def counting_sort(arr: list[int]):
= min(arr)
mi = max(arr)
ma list[int] = [0] * (ma - mi + 1) # value range
count: for x in arr:
- mi] += 1
count[x
list[int] = []
result: for i in range(mi, ma + 1):
for _ in range(count[i - mi]):
+ mi)
result.append(i
return result
print(f"{counting_sort([2, 1, 4, 3, 5])=}") # [2, 3, 4, 5, 6]
print(f"{counting_sort([-1, -3, -2, 5, 6])=}") # [-6, -5, -4, 2, 3]
Now, the memory is coming back.
What is the intuitive explanation for counting sort? - Quora
Intuition:
Counting sort works because we limit the range of possible input values. By interating over the range of possible values in sorted order, we ensure that the values we add to our output array are always added in sorted order.
TODO: Study Radix Sort
Protein bars 450 Protein shake 150 Sushi bowl 800 Sausage & pancake 250 Sandwich 150 Boba 400
Total 2200 kcal
MUST:
TODO: