During the interview, I was asked to indicate the names of the files in the directory and its subdirectories¹, using neither recursion, nor stack, nor queues.
Since the only non-recursive way I know is using the stack, I was not able to answer this question.
The interviewer explained this decision, but I could not understand it. The only thing I remember is that it uses two methods instead of one.
What is this approach that allows you to list files in a directory and its subdirectories without recursion and without a stack or queue?
¹ The solution is a language agnostic. A list of subdirectories is provided by the method ListDirectories(string directoryPath), and files by ListFiles(string directoryPath). We do not know in advance the depth of the subdirectories.
source
share