Let’s exercise at leetcode?

What is leetcode ?

Well it’s the kind of question you are getting asked during interviews. That’s why I’m doing that.

Sorting

Let’s try to implement a sorting algorithm. We will start simple with bubble sort. Given an unsorted array, we want to sort it. The idea is simple we start at index $0$ and $1$. If array[0] > array[1] we swap them, we then check 0,

python
1
2
3
4
5
6
7
def bubbleSort(ls: list[int]) -> list[int]:
    n = len(ls)
    for i in range(n):
        for j in range(i,n):
            if ls[i] > ls[j]:
                ls[i], ls[j] = ls[j],ls[i]
    return ls

We