Leetcode: Google interview questions - Round 2 - #3 - 他人汇总



Leetcode: Google interview questions - Round 2 - #3 - 他人汇总

莉蔻三九九及其变种(汇率)
频率:21
就是一个2维数组里的有人和自行车,要每个人匹配到一辆自行车,人和自行车的距离越短越好,没有距离相同的情况。就是算出所有的距离然后放到heap里慢慢pop出来,记录下人和车的状态就可以了。
频率:13
 再跟一下

利口六八四 六八五及其变种(bst删除额外边)
频率:10
-baidu 1point3acres
利口六二
著名变种:DP。给定一个矩形的长宽,用多少种方法可以从左上角走到右上角 (每一步,只能向正右、右上 或 右下走):整个矩形遍历做DP即可,不需要想复杂. 牛人云集,一亩三分地
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static void main(String[] ss) {
 
 
    System.out.println(ways(7, 6));
}
 
public static int ways(int m, int n) {
    int[][] dp = new int[m + 2][n];
    dp[1][0] = 1;
 
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m + 1; j++) {
            dp[j][i] = dp[j - 1][i - 1] + dp[j][i - 1] + dp[j + 1][i - 1];
        }
    }
 
    return dp[1][n - 1];
}
-follow up:如果给矩形里的三个点,要求解决上述问题的同时,遍历这三个点 (切割矩形,一个一个地做DP,然后相加)
Solution, 所有路径必须经过这3个点,求一共有多少种走法(到达右上)
其实这3个点跟起点和终点没有区别。如果存在这3个点,则这5个点中的任意2个点不可能存在在一个column上。按column来划分矩形,分别对两两做dp
可以写一个方法
int ways(int m, int n, int[] start, int[] end, int startCount) 来避免代码重复

-follow up:如何判断这三个点一个是合理的,即存在遍历这三个点的路经
Solution
2个相邻之间的点的连线与水平线的夹脚 <= 45度,就可以说明左边的点能到达右边的点。表示为 |y2 - y1| >= x2 - x1, 假设(x1, y1) (x2, y2) 为左右2点

-follow up:如果给你一个H,要求你的路径必须向下越过H这个界,怎么做 (别问我,我不会)
Solution
找出不越界的路线个数,原来的结果相减就得到越过的个数

楼主这题试一试用镜像做,也就是说重点不在(W, 0), 而在(W, 2H), W是矩阵的宽度
频率:9
六口把四散(猜词)
843
频率:9

Read full article from Leetcode: Google interview questions - Round 2 - #3 - 他人汇总


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts