
To sort squares of a sorted array, you don’t want to use any sorting algorithms such as bubble sort. Because it takes O(nlogn) ~ O(n^2) time. Here we introduce a better way to sort in one pass. The solution is using two pointers. Initialize two pointers, one points to the …
Continue reading