面了两次Data Platform组,一次内推,一次海投,因为用的不同名字和邮箱,给了两次机会,但都是Onsite挂了,看来还是和奈妃差了点缘分,回馈地里攒攒人品
第一次
店面 Weighted Cache
Onsite
多线程轮: 考一个加锁问题,忘了具体题目,现场写的磕磕绊绊的。是跟 double checked locking 相关的
系统设计: Config Deployment System, roll out config across the globe,有点CICD的感觉
Coding: Inverted Index:
package netflix;
import java.util.*;
public class OptimalDocumentSearch {
private final List<String> documents;
// word -> (docId -> list of positions)
private final Map<String, Map<Integer, List<Integer>>> index;
public OptimalDocumentSearch(List<String> documents) {
this.documents = documents;
this.index = new HashMap<>();
buildIndex();
}
private void buildIndex() {
for (int docId = 0; docId < documents.size(); docId++) {
String[] words = documents.get(docId)
.toLowerCase()
.split("\\s+");
for (int pos = 0; pos < words.length; pos++) {
String word = words[pos];
index
.computeIfAbsent(word, k -> new HashMap<>())
.computeIfAbsent(docId, k -> new ArrayList<>())
.add(pos);
}
}
}
public List<String> search(String phrase) {
String[] words = phrase.toLowerCase().split("\\s+");
if (words.length == 1) {
return singleWordSearch(words[0]);
}
return phraseSearch(words);
}
private List<String> singleWordSearch(String word) {
Map<Integer, List<Integer>> posting =
index.getOrDefault(word, Collections.emptyMap());
List<String> results = new ArrayList<>();
for (int docId : posting.keySet()) {
results.add(documents.get(docId));
}
return results;
}
// Must contain all words, get all documents for first word, iterate through each doc and positions of first word in that doc
// Check if following words also show up in this doc in the consecutive positions
private List<String> phraseSearch(String[] words) {
if (!index.containsKey(words[0])) {
return Collections.emptyList();
}
Map<Integer, List<Integer>> firstPosting = index.get(words[0]);
List<String> results = new ArrayList<>();
// Check only documents that contain the first word
for (int docId : firstPosting.keySet()) {
List<Integer> candidatePositions = firstPosting.get(docId);
boolean matchFound = false;
for (int pos : candidatePositions) {
if (matchesAtPosition(docId, pos, words)) {
matchFound = true;
break;
}
}
if (matchFound) {
results.add(documents.get(docId));
}
}
return results;
}
private boolean matchesAtPosition(int docId, int startPos, String2() {
Map<String, Object> json = new HashMap<>();
json.put("fname", "masked_first_name");
json.put("lname", "masked_last_name");
Map<String, Object> contacts = new HashMap<>();
contacts.put("home", "12345");
json.put("contacts", contacts);
return json;
}
private static Map<String, Object> createTestJson3() {
Map<String, Object> json = new HashMap<>();
json.put("fname", "masked_first_name");
Map<String, Object> lname = new HashMap<>();
lname.put("cell", "+1(888).999.9999");
lname.put("home", "+1(555).333.3333");
json.put("lname", lname);
Map<String, Object> contacts = new HashMap<>();
contacts.put("cell", "+1(999).999.9999");
contacts.put("home", "+1(333).333.3333");
json.put("contacts", contacts);
return json;
}
private static Map<String, Object> createTestJson4() {
Map<String, Object> json = new HashMap<>();
json.put("fname", "masked_first_name");
json.put("lname", "masked_last_name");
Map<String, Object> contacts = new HashMap<>();
contacts.put("cell", "+1(999).999.9999");
contacts.put("home", "+1(333).333.3333");
json.put("contacts", contacts);
return json;
}
} |