Clash of Coders CLCO01 - Editorial

PROBLEM LINK:

Practice

Contest

Author: Nikhil Khurana

Tester: Rahul Johari

DIFFICULTY:

SIMPLE, EASY.

PREREQUISITES:

Stacks

PROBLEM:

Given two commands pwd and cd and a directory path, you are required to print the current working directory whenever you encounter pwd command.

QUICK EXPLANATION:

pwd - this command prints the current working directory,

cd - used to change the current working directory.

EXPLANATION:

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.

I went through the solution attached, I am still not able to get it.

1 Like