Author: Nikhil Khurana
Tester: Rahul Johari
Given two commands pwd and cd and a directory path, you are required to print the current working directory whenever you encounter pwd command.
pwd - this command prints the current working directory,
cd - used to change the current working directory.
Implement with stack. If the string begin with ‘/’, let top = 0, else remain at the top; Then
process the substring one by one, when meeting “…” , top–;
else remain at the top.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.