3 ms·
It's not a LeetCode problem but I'd be impressed if someone can come up with the 4-liner recursive solution for the Tower of Hanoi problem. https://cses.fi/pro
by Ismail-Maj 4y ago
It's not a LeetCode problem but I'd be impressed if someone can come up with the 4-liner recursive solution for the Tower of Hanoi problem.
https://cses.fi/problemset/task/2165 https://cses.fi/problemset/task/2165
https://www.mathsisfun.com/games/towerofhanoi.html https://www.mathsisfun.com/games/towerofhanoi.html
https://www.geeksforgeeks.org/c-program-for-tower-of-hanoi/ https://www.geeksforgeeks.org/c-program-for-tower-of-hanoi/
- roflyear 4y agoYeah it is a weird problem. I actually got asked a similar problem about seven or eight years ago (but was not presented as a tower of hanoi problem) - and the interviewer asked if I could come up with a closed-form solution. I think one does exist and is not too crazy to understand but that was a trip.
- sudosysgen 4y agoYou can use the the recursive solution to generate the closed form solution. The interviewer was asking you for the closed form solution to see if you could exactly compute the complexity of a recursion.