-
又是纯数学题. Black Jack.
给你infinity张牌. Card value 1到10. Find the probability that a card will bust. P(bust|x=hand)
玩家17 to 21时赢, 超过21 bust.
答案:Leetcode 837 -
给你N幅画. 每幅画都有price和quality. 用最低价格买K幅画, with 0<K<=N
Constraint: 买的画必须遵守minimum price for 那幅画. 用了一个ratio来买一幅画, 剩余的K-1幅画都要遵守这个ratio.
答案:Leetcode Minimum Cost To Hire K Workers -
i. 给你一个tree. 里面多了一条edge, 所以不是binary tree了. Remove 那个多余的edge.
ii. Implement power(x,y) st it returns x^y. Optimize 它
答案:1.
2.二分法解决,时间是O(logn)。
public double myPow(double x, int n) {
if (n == 0)
return 1;
double res = myPow(x, n / 2);
return n % 2 == 0 ? res * res : n < 0 ? res * res * (1 / x) : res * res * x;
}
-
i. 猜字游戏. 给你一个secret word, 一个guess word. Return <number of words that is guessed correctly and at correct position, number of words that is guessed correctly but at wrong position>
ii. 迷宫. 给你一个有一些墙的迷宫. 怎么从start去到end.
答案:Leetcode Guess the word -
一个俄罗斯小哥, 人狠话不多.
给你一个infinite size length array, 和list of queries in the format of <i,j>, find the maximum number from index i to index j in array.
答案:区间树