Google 2020 New Grad OA

两道 LeetCode 看到的原题。

第一道是 Watering Plants,第二道是 Minimum Domino Rotations For Equal Row,连顺序都没变,不太理解…

解法直接看链接里的评论/Discussion,但是没底,因为 Google 不给 Test case,不知道是不是真的能过…另外还听说 Google OA 完被简历拒?

2 Likes

如果能够pass test cases,不应该被简历拒啊

不是会有一两个简单的 test case么

对,会有简单的test case,但是总觉得有坑但是又想不出什么好的 testcase。。。可能是前两天做Twitter被坑的后遗症吧。。

被简历拒的不是我,是我听说的。。。

是不是GPA太低了?

具体不知道。。Google 有 GPA Bar?

总不能低于3吧

这我就不知道了,我GPA没那么低,只是听说有人遇上了这事。。

那确实少见,谷歌一般OA以后很少挂简历(OA做错了除外)

不知道,等等看吧。。希望我能有后续

嗯,会有的

截图贴一下

Domino Rotation

public int solution(int[] A, int[] B) {
        // write your code in Java SE 8
        if(A.length==0 && B.length==0)
            return 0;
        if(A.length==0 || B.length==0)
            return -1;
        return minDominoRotations(A, B);

    }
    public int minDominoRotations(int[] A, int[] B) {
    int n = A.length;
    int rotations = check(A[0], B, A, n);
    if (rotations != -1 || A[0] == B[0]) return rotations;
    else return check(B[0], B, A, n);
  }
    public int check(int x, int[] A, int[] B, int n) {
    int rotations_a = 0, rotations_b = 0;
    for (int i = 0; i < n; i++) {
      if (A[i] != x && B[i] != x) return -1;
      else if (A[i] != x) rotations_a++;  
      else if (B[i] != x) rotations_b++;
    }
    return Math.min(rotations_a, rotations_b);
  }

Frequent Email Addresses

public int solution(String[] emails) {
        // write your code in Java SE 8
        HashMap<String, Integer> hs = new HashMap();
        for(String email: emails){
            StringBuilder sb = new StringBuilder();        
            int at_index = email.indexOf("@");
            int plus_index = email.indexOf("+");
            if(plus_index == -1){
                sb.append(email.substring(0,at_index).replace(".", ""));
            }else{
                sb.append(email.substring(0,plus_index).replace(".", ""));
            }
            sb.append(email.substring(at_index));
            String s = sb.toString();
            hs.put(s,hs.getOrDefault(s,0)+1);
//            hs.add(sb.toString());
        } 
        int max = 0;
        //String maxs = "";
        for(String key: hs.keySet()){
            if(hs.get(key) > max){
                max = hs.get(key);
                //maxs = key;
            }
        }
        return max;
    }

Lottery Coupons

public int solution(int[] coupons) {
        // write your code in Java SE 8
        HashMap<Integer, Integer> hm = new HashMap();
        int price = Integer.MAX_VALUE;
        for(int i = 0; i<coupons.length; i++){
            int c = coupons[i];
            if(hm.containsKey(c)){
                price = Math.min(price, i-hm.get(c) + 1);
            }
            hm.put(c,i);
        }
        return price == Integer.MAX_VALUE ? -1 : price;
    }