Solution on java is actually O(n^2)

Firstly, factorial is calculated every time, which takes O(n). This can be fixed by calculating it only once for all N and saving it in an array.

Secondly, removing an item from an ArrayList is O(n). If you want O(1), you must use a LinkedList to get it in O(1)

Please fix the solution.


The course is updated. Kindly have a look again.