## Sollicitatievraag

Sollicitatiegesprek voor de functie Software Developer

-Amsterdam

# Union of n arrays with x elements. Output common members contained in at least 2 arrays. Explain the complexity of the algorithm used. We have a digested server log with username, visited page and timestamp. Create a processing algorithm that will output the most visited page/areas in such a way that will match partial path as well. i.e. { { user: "user1", page="/home" }, { user: "user1", page="/home/account" }, { user: "user1", page="/home/account/profile" }, { user: "user1", page="/home/account/login" }, { user: "user2", page="/about" }, { user: "user2", page="/about/contact" }, { user: "user2", page="/home" } } the output user1 - home/account - home user2 - /about PS I'm rephrasing because I cannot recall exactly the question

Antwoord

## Antwoorden op sollicitatievragen

4 antwoorden

1

I don't think your solution is what they want. I think they wanna see how you tackle the problem.

Anoniem op

0

Parse Log op

0

The first approach that will work and is time complexity wise efficient is that of hash map. Pseudo code: Sort the given input by userid; Create a hashmap hm; // for c++ you can use unordered_set string previous_userId; for userId, page in sortedinput: if previous_userId is not equal to userId // create output of previous_userId using hm for key, value in hm if value >= 2 add it to userId's output clear hm previous_userId = userId for each valid_prefix_page in page // like for page = /home/account valid_prefix_pages would be /home and /home/account if valid_prefix_page exists in hm then add it to hm with key as valid_suffix_page and value as 1 else increase value (corresponding to valid_prefix_page) by 1 This solution works fine. But we can optimize memory by using trie instead of hashmap and storing value at each "/" node of how many times a prefix has occured.

Anoniem op

0

Union of n arrays with x elements. Output common members contained in at least 2 arrays. ---------------------------------------------------------------------------------------------------------------------------------------------- Simple bruteforce solution(won't work if array1 or array2 is empty): private static List intersect(int[] array1, int[] array2, int[] array3) { Set result = new LinkedHashSet(); for(int i = 0; i (result); } There are more effective solutions based on putting elements into the map.

Anoniem op

## Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.