Intuition
In a way, we are just required to keep the track the maximum depth of the file structure.
Minimum number of operations to go back after folder changes = Maximum depth of file tree
This way, there’s no need to keep track of current folder we are in, just need what’s our depth after all operations are done.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we iterating over all operations.
-
Memory
The memory usage is since we are not using any extra data structure.
— A