Mental Model
Find the next bigger arrangement of numbers by changing the smallest part possible. If none exists, start over with the smallest arrangement.
Analogy: Imagine you have a combination lock with digits. To get the next code, you try to increase the last digit. If it can't go higher, you move left until you find a digit you can increase, then reset the digits to the right to the smallest order.
Array: [1, 2, 3, 4]
Indexes: 0 1 2 3
We look from right to left to find where the order breaks:
Example: 1 -> 2 -> 3 -> 4
↑
pivot here if next number is larger