Need Help with Microsoft Interview Question
Anonymous User
260
May 18, 2023
May 18, 2023
In a recent interview with Microsoft for SSE role I have been asked below question.
You are given two functions
- List listAllUrls(String url) -> you can pass a URL link to a web page to this function and it will return all the URLs on that page
- Boolean isWorking(Sting url) -> this funtion will validate the URL, if it is working then true otherwise false.
Write a program to return all the non-working / invalid URLs till the last depth.
My Answer:
private void helper(HashSet<String> validUrls, HashSet<String> inValidUrls, String baseUrl) {
List<String> urls = listAllUrls(baseUrl);
for( String url : urls ) {
if(isWorking(url) {
if(!validUrls.contains(url) && !inValidUrls.contains(url)) {
helper(validUrls, inValidUrls, url);
validUrls.add(url);
}
} else {
inValidUrls.add(url);
}
}
}
public List<String> getInvalidUrlsList(String baseUrl) {
HashSet<String> validUrls = new HashSet<>();
HashSet<String> inValidUrls = new HashSet<>();
helper(validUrls, inValidUrls, baseUrl);
ArrayList<String> result
= new ArrayList<>(inValidUrls);
return result;
}Follow up question :
- how decress this program complexity ? > I have no other approch to incress the performance
- Design a low HDL for the same ? -> I have designed a HDL
Interview feedback came nagavtie. Can anyone suggest what cloud I have done better in this code or can point to similar problem.
Thanks in advance.
Comments (3)


