Total Experience: 10+ Years
Current Domain: Embedded (OS libraries)
Current Location: India
Tool used for virtual Interview: BlueJean, coderPad.
Interview Date: Last week of August 2020
Interview Time slot: 45 minutes
Phone Screening Round Questions:
Design a Hashmap with additional feature "Last". Code required for put, get, delete and last methods.
Note:
Example:
Input:
[put({1, ‘a’}), put({2, ‘b’}), put({3, ‘c’}), last(), last(), get(1), last(), last(), last(), last(), delete(1), last(), last(), last()]
Output:
[3, 2, 1, 3, 2, null, 3, 2, null]Explanation:
Solution given:
To optimise the searching in double linked list, I saved iterator in the map.
Time taken: around 15 min including dry run.
Write a program to resolve the path for unix platfrom. Function signature is like:
string resolvePath(string currentDirectory, string expectedDirectory, int maxLength)
currentDirectory: Path of directory where you are currently present
expectedDirectory: Path of directory which we want to resolve. It may be absolute path or relative path.
maxLength: max length of return path allowed.
return: absolute path of directory under length given.Example:
Input:
currentDirectory: /root/abc/def/ghi
expectedDirectory: ./../jkl/mno
maxLength: 20Output:
/root/abc/def/jkl/Explanation:
Solution given:
Identify the path is absolute or relative by first character (/ or not).
If absolute path then call removePathBasedOnLength.
If relative path then append both paths.
a. Whenever there is pattern /./ then replace it with /
b. Whenever there is pattern /../ then skip substring from “/” present before pattern till this last index of pattern.
c. Call removePathBasedOnLength after removing all patterns of /./ and /../
removePathBasedOnLength method check last directory within maxLength and return that path.
Interviewer suggested me to improve it then I had given another solution based on stack as below
Identify the path is absolute or relative by first character (/ or not).
If absolute path then call removePathBasedOnLength.
If relative path then
a. Traverse left to right in the currentDirectory path and push all directories in stack. Stack will look like [“root”, “abc” , “def”, “ghi”]
b. Traverse left to right in the expectedDirectory and if “.” then skip, else if “..” then pop one directory, else push in stack.
c. Construct the path using stack entries and then call removePathBasedOnLength.
removePathBasedOnLength method check last directory within maxLength and return it.
Time taken: around 30 minutes, unabled to complete dry run.
I tried to test my code in IDE and found 2 mistakes after interview.
Today, Got an email from recruiter that my feedback is on borderline. So, they can’t proceed further.