Need Help with Microsoft Interview Question
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2023-05-18Added By Anonymous
Source: Link
In a recent interview with Microsoft for SSE role I have been asked below question.
You are given two functions
1.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
2.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:
1private void helper(HashSet<String> validUrls, HashSet<String> inValidUrls, String baseUrl) {
2
3 List<String> urls = listAllUrls(baseUrl);
4
5 for( String url : urls ) {
6
7 if(isWorking(url) {
8 if(!validUrls.contains(url) && !inValidUrls.contains(url)) {
9 helper(validUrls, inValidUrls, url);
10 validUrls.add(url);
11 }
12 } else {
13 inValidUrls.add(url);
14 }
15 }
16}
17public List<String> getInvalidUrlsList(String baseUrl) {
18
19 HashSet<String> validUrls = new HashSet<>();
20 HashSet<String> inValidUrls = new HashSet<>();
21
22 helper(validUrls, inValidUrls, baseUrl);
23 ArrayList<String> result
24 = new ArrayList<>(inValidUrls);
25
26 return result;
27}Follow up question :
1.how decress this program complexity ? > I have no other approch to incress the performance
2.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.