Qualcomm Interview Question for Software Engineers
- 0of 0 votes
AnswersComplete the puzzle which simulates generic directory structures.
- Sameer July 21, 2017 in United States
* The solution should be directory agnostic.
* Be succinct yet readable. You should not exceed more than 200 lines.
* Consider adding comments and asserts to help the understading.
* Code can be compiled with javac Directory.java
* Code should be executed as: java -ea Directory (-ea option it's to enabled the assert)
*/
/**
* change the code here.
*/
class Shell {
Shell cd(final String path) {
return this;
}
public String path() {
return "/";
}
}
public class Directory {
public static void main(String[] args) {
final Shell shell = new Shell();
assert shell.path().equals("/");
shell.cd("/");
assert shell.path().equals("/");
shell.cd("usr/..");
assert shell.path().equals("/");
shell.cd("usr").cd("local");
shell.cd("../local").cd("./");
assert shell.path().equals("/usr/local");
shell.cd("..");
assert shell.path().equals("/usr");
shell.cd("//lib///");
assert shell.path().equals("/lib");
}
}| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer
Interview Type: Written Test