注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
网银全套。
第一轮coding。白人小哥。neighbor words. lc 127.建个graph 然后bfs。还行。
第二轮coding。中国小哥。- /**
- Question:
- Let’s say on the website, we keep track of what specific pages/products members are viewing, for things like business metrics.
- Every time somebody comes to the website, we write a record to a log file consisting of Timestamp, PageId, CustomerId. At the end of the day we have a big log file with many entries in that format. And for every day we have a new file.
- Now, given two log files (log file from day 1 and log file from day 2) we want to generate a list of ‘loyal members’ that meet the criteria of: (a) they came on both days, and (b) they visited at least two unique pages.
- */
复制代码 答案放后面大家自己参考。
第三个印度大哥senior staff 面SD。让你design 一个gift card的系统,可以track user的gift cards, 还有balance。然后如果用户消费了,第三方会有消息过来,你怎么处理和update eedback不错。但是差点,只能给ic3 。
Recruiter说感觉给你直接发offer也没啥意义,你考虑一下。
十动然拒。
大家给点米好不好?发的面经都没有米,没有动力了啊。- public class Solution {
- public static void main(String[] args) {
- String[][] log1 = new String[][]{{"t11", "p1", "c1"}, {"t12", "p2", "c2"}, {"t13","p3", "c3" }, {"t13","p4", "c4" }, {"t14","p2", "c4" }};
- String[][] log2 = new String[][]{{"t21", "p1", "c1"}, {"t22", "p1", "c2"}, {"t23","p3.1", "c3" }};
-
- Set<String> result = identify(log1, log2);
- System.out.println(result);
-
-
- String[][] log11 = new String[][]{{"t11", "p1", "c1"}, {"t12", "p2", "c1"}, {"t13","p3", "c1" }, {"t13","p4", "c4" }, {"t14","p2", "c4" }};
- String[][] log21 = new String[][]{{"t21", "p1", "c1"}, {"t22", "p5", "c1"}, {"t23","p3.1", "c3" }};
- Set<String> result2 = identify(log11, log21);
- System.out.println(result2);
- }
-
-
- public static Set<String> identify(String[][] list1, String[][] list2) {
- // identify the common customers within the 2 list,
- // count of the visite page uniquely > 2
-
- // iterate the list1, identify all unique customers => set of customer set1
- // ietrate the list2, => if a customer is in set1 => first => set 2
-
- // iterate the customers in set2 identify the unique customer
-
- // list1 => transform into a map => customerid => set of pageIds
- // LIST2 => TRANSFORMA into a map => customer id => set of pageIds
- //
-
- /**
-
- m log1 n log2
-
- O(m) + O(n) => O(max(m, n));
-
- let the unique customers be k, the maximum page visited j
-
- K => J
-
- O(max(k, j))
-
-
- O(m + n);
-
- compare the size of the 2 input, and construct a map using the short list,
- => O(min(m, n)); => if size of the value is >= 2; drop => skip
-
-
- */
-
- // set result => Map<String, String> result : customer id to timestamp map
- Set<String> result = new HashSet<>();
-
- Map<String, Set<String>> map = new HashMap<>(); // map => set of unique pages
-
- for (String[] log: list1) {
- // String ts = log[0];
- String pageId = log[1];
- String customerId = log[2];
-
- map.putIfAbsent(customerId, new HashSet<>());
- map.get(customerId).add(pageId);
- }
-
- for (String[] log: list2) {
- String pageId = log[1];
- String customerId = log[2];
- if (!map.containsKey(customerId)) { // customer didn't visite yesterday
- continue;
- }
-
- if (map.get(customerId).size() < 2) { // only add if customer < 2
- map.get(customerId).add(pageId);
- }
- if (map.get(customerId).size() >= 2) {
- result.add(customerId); // result.put(customerId, Math.max(map.get(customerId), timestamp));
- }
- }
-
- return result;
-
- }
- }
复制代码 |