注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Interview2: Problem Solving (CODING) + 2 Leadership Principles
Interview3: Logical and Maintainable (CODING) + 2 Leadership Principles
早上刚和recruiter电话, 但是我不是很懂这两轮考什么?
Recruiter给了这两个例子。
这个logical and maintainable感觉和OA差不多。
我看problem solving 的例子, find file matcher, 感觉这不就是OOD吗? 我问他, 他说不是OOD。
问一下大家了解这个吗?
另外两轮是SD和coding。L5.
Logical and Maintainable
Amazon wants to build a lottery system. When a customer purchases items worth between $1 and $100, then they are entered into the lottery. Customers that purchase an item for $10 should be 10 times more likely to win the lottery than customers who have purchased an item for $1 [i.e. there is a linear relationship between the amount a customer purchased an item for and their probability of winning]. Write a function that takes a list of customers and purchase price as input. As output, it should return K winners.
import random
import heapq
class Customer:
def __init__(self, id, price):
self.id = id
self.price = price
def get_k_lottery_winners_brute_force(customers, k):
entry_list = []
result = []
for customer in customers:
for i in range(0, customer.price):
entry_list.append(customer.id)
for i in range(0, k):
result.append(random.choice(entry_list))
return result
def get_k_lottery_winners_heap(customers, k=1):
sorted_customers = []
result = []
customer_dict = {}
# Combine prices for each customer
for customer in customers:
if customer.id in customer_dict:
customer_dict[customer.id] += custo extends LogicalFileMatcher {
public AndMatcher(FileMatcher left, FileMatcher right) {
super(left, right);
}
@Override
public boolean matches(FileObject file) {
return left.matches(file) && right.matches(file);
}
}
public class OrMatcher extends LogicalFileMatcher {
public OrMatcher(FileMatcher left, FileMatcher right) {
super(left, right);
}
@Override
public boolean matches(FileObject file) {
return left.matches(file) || right.matches(file);
}
}
public class SymbolicLinkAwareFileSearch {
public static List<FileObject> findFiles(File directory, FileMatcher matcher) throws IOException {
List<FileObject> results = new ArrayList<>();
if (directory.exists() && !isSymbolicLink(directory)) {
File[] files = directory.listFiles();
// Rest of the code...
}
return results;
}
// Rest of the code...
} |