Sollicitatievraag

Sollicitatiegesprek voor de functie Software Developer

-Amsterdam

Booking.com

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

package com.epam.practice.java8; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class ParsingLog { public static void main(String[] args) { ParsingLog.User u1 = new ParsingLog.User("U","/home"); ParsingLog.User u2 = new ParsingLog.User("U","/home/account"); ParsingLog.User u3 = new ParsingLog.User("U","/home/account/profile"); ParsingLog.User u4 = new ParsingLog.User("U","/home/account/login"); ParsingLog.User u5 = new ParsingLog.User("V","/about"); ParsingLog.User u6 = new ParsingLog.User("V","/about/contact"); ParsingLog.User u7 = new ParsingLog.User("V","/home"); List userObject = new ArrayList(); String DELIEMETER = "/"; Map> structureMap = new HashMap(); userObject.add(u1); userObject.add(u2); userObject.add(u3); userObject.add(u4); userObject.add(u5); userObject.add(u6); userObject.add(u7); for(User user : userObject){ StringBuilder temp = new StringBuilder(); String[] entry = user.getPath().split("/"); Map current = initMap(structureMap, user.getName()); for(int i = 1; i initMap(Map> structureMap, String userName) { if(structureMap.get(userName) == null) structureMap.put(userName, new HashMap()); return structureMap.get(userName); } public static class User{ private String name; private String path; public User(String name, String path) { super(); this.name = name; this.path = path; } public String getName() { return name; } public String getPath() { return path; } } }

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.