© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Amr Saber
software engineering
The order of the old implementation is not O(n^3) it's O(3^n) as you branch 3 times for each call, and you have total n different cases, so it's 3 * 3 * 3 * 3 ... n times which is 3^n.
Amit Mehta
Javascript Developer who Loves to Code!
Kudos for catching that! 👍