找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 11264|回复: 28
收起左侧

[米群网大牛独家面经总结] 帮人发几个面经

  [复制链接]
发表于 12-5-2014 02:19 PM | 显示全部楼层 |阅读模式

亲!马上注册或者登录会查看更多内容!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
声明: 我是帮人发的,顺便感谢下提供资源的人~~
; }- f+ h. G3 v. ]+ o: q" U
Google:
- h6 l/ D2 I( m+ ?" G
Please use this Google docto code during your interview. To free your hands for coding, we recommend thatyou use a headset or a phone with speaker option.) h4 t9 y- `) L1 p$ F

9 n! j& T( d2 l! Y4 X4 A* A3 E  r

3 G& D/ f$ a; Y- \
public class Foo {
   private final int i;
   private final String s;
   public Foo (...)
   public int hashcode() {
       returni * s.length();
   }
   public booleanequals(Object f) {
       returnf != null && f instanceof(Foo) && this.i == ((Foo) f).getI()&& s.equals(((Foo) f).getS());
   }
}
: }6 `, K# r+ k6 M( @: F8 [7 n
Iterable<String> lines
public List<String>getNonDuplicateLines(List<String> lines) {
   Map<String, Integer>map = new HashMap<String, Integer>();
   for(String s : lines) {
       if(!map.containsKey(s))
           map.put(s,1);
       else
           map.put(s,map.get(s) + 1);
   }
   Set<String> keySet =map.keySet();
   List<String> result =new ArrayList<String>();
   for(String key, keySet) {
       if(map.get(key)== 1) {
           result.add(key);
       }
   }
   return result;
}
5 e9 v! A) n  X; D' Q
Find the number of occurrences of a value ina sorted array of ints.
, z6 I- O# a1 k) `  d8 l; c
1,1,2,2,2,3,4,5,5
public int findOccurrences(int[] arr, target){
   int left = -1;
   int right = -1;
   int low = 0, high =arr.length - 1;
   int pivot = -1;
   while(low <= high) {
       intmid = low + (high - low) / 2;
       if(arr[mid]== target) {
           pivot= mid;
           break;
       }
       elseif(arr[mid] < target)
           low= mid + 1;
       else
           high= mid - 1;
   }
   if(pivot == -1)
       return0;
   left = right = pivot;
   low = 0, high = pivot - 1;
   while(low <= high) {
       if(arr[high]< target)
           break;
       intmid = low + (high - low) / 2;
       if(target<= arr[mid]) {
           if(target== arr[mid]) {
               left= mid;
           }
           high= mid - 1;
       }
       else{
           low= mid + 1;
       }
   }
   low = pivot + 1;
   high = arr.length - 1;
   while(low <= high) {
       if(arr[low]> target)
           break;
       intmid = low + (high - low) / 2;
       if(target>= arr[mid]) {
           if(target== arr[mid])
                right= mid;
           low= mid + 1;
       }
       else
           high= mid - 1;
   }
   return right - left + 1;
}
Google
llease use thisGoogle doc to code during your interview. To make hands free coding a littleeasier, we recommend that you use a headset or a phone with speaker option.7 M. J9 O' C. Z. t

6 m- `6 X& w+ J4 ~Best,3 I* D! s- A8 ~6 ?2 S9 f6 Y# Y+ `
Google Staffing
5 N+ }: @" h2 Q3 y0 Z$ B6 l
4 @. b; f8 Q2 u+ s9 p+ a. {4 V0 f3 x5 }
1 P# Y* g; V; N; c
  L! Y8 U, D' ^4 z5 W+ Z
Leaderboard
1  A  50000
2  B  45000
3  C    3000
Player {
            Name;
            score
}
getByRank();
updateByName();
//a^b
public double pow(int a, int b) {
            if(b== 0) {
                        return1;
} else if(a == 0){
            return 0;
} else {
            if(b < 0) {
                        if(b >Integer.MIN_VALUE) {
                                    } else {
            return (double)1 / pow(a, -b); // (1<< 31) - 1; (1 << 31)
return(double)1 / pow(a, Integer.MAX_VALUE) / a;
}
}else {
            double half = pow(a, b / 2);
            double res = half * half;
            if(b % 2 == 1) {
                        res *= a;
}
returnres;
}
}
}
time : O(lg b)
[0, 3, 1, 2, 0, 0, 5] -> [3, 1, 2, 5, 0,0, 0]
private void swap(int[] num, int p, int q) {
            if(p!= q) {
                        inttmp = num[p];
                        num[p]= num[q];
                        num[q]= tmp;
}
}
public void solve(int[] num) {
            if(num== null || num.length == 0) {
                        return;
}
int cur = 0;
int end = 0;
while(cur <num.length) {
            if(num[cur] != 0) { // 0, 3, 1, 2,0,0, 5
                        swap(num, cur ++, end++) // cur, end: 2, 1; 3,2; 4, 3; 7, 4
}else {
            ++ cur; // 1, 5, 6
}
}
}
[3, 0, 1]

' L' ~' h$ T: w* i" @& e8 D6 L# s  h) z" _
Facebook:
Phone number combination

" @% w/ {0 @1 {5 O) B+ @6 _) H# Z
Linkedin:
Flip binary tree
Max subarray sum/ product
+ g% y. Q1 r# C+ C. R
4 n# B! l! {! }/ z* {9 W

- y% ]! [+ R7 @8 V* T( @% F
Linkedin Onsite
1.    Manager: 项目介绍 极其详细
2.    Design: Amazon Product Webpage
3.    Coding: House Painting + followup
Max Points
4.    Coding: Minimum Window
Sqrt (Double)

! p" J' T" S$ j7 I: \$ o7 w0 b/ `0 q" m' ~# C* I# P
Hulu Phone
Helo, Xiao!

& U4 @: w. g; ], w, T0 L" b
RANSOM NOTE

; {; V1 ]" ^' P
- Someone wants to send amessage, but they do not want to give away their handwriting
- So they have a message,and they cut out letters in a magazine to make the message
5 P- L* J% U( a8 Y
message: "Give me1000 dollars"
magazine: "My name isgiven to be today 10000 dollar"

" h+ G5 p; z) P; R" W9 U2 x
Want to write a message,by cutting out letters in a magzine.
& P( D5 h" U9 x
- does the magazinecontain enough of the letters from my message
! J, S$ f5 `. U+ c5 q7 v* j$ [% p
// returns true when thereare enough letters in the magazine to make the message
// assume all uppercase
// ignore punctuation
' `7 o! z' n2 ]  Z- F
private voidplusOne(Map<Character, Integer> map, char key) {
   map.put(key, map.containsKey(key) ? map.get(key) + 1 : 1);
}
1 F6 C$ c! J/ W: u" [2 [, n
private voidreduceOne(Map<Character, Integer> map, char key) {
   if(map.get(key) == 1) { map.remove(key); }
    else {map.put(key, map.get(key) - 1);
}

( W. ?+ {  V* e) n/ `0 G8 a; _
public booleancanCreateRansomNote(String message, String magazine) {
    Map<Character, Integer> table = newHashMap<Character, Integer>();
    for(inti = 0; i < message.length(); ++ i) {
       plusOne(table, message.charAt(i));
    }
    for(inti = 0; i < magazine.length() && !map.isEmpty(); ++ i) {
       char c = magazine.charAt(i);
       if(map.containsKey(c)) { reduceOne(map, c); }
    }
    returnmap.isEmpty();
}

; g0 C5 P. L5 s6 C  _3 G
CHEMiCAL EQUATION PARSING
  v2 c. i2 O" N/ V' W6 E0 m
H20 - {H: 2, O: 1} -["H", "2", "O"]

1 d* G8 {# i) c
NaCl - {Na: 1, Cl: 1} -["Na", "Cl"]

, D! y6 w& D" g* u8 a2 S, T
O(H(UO)2)3 - {O: 7, H: 3} -["O", "(", "H", "(", "O","2", ")", "3"]

3 f& @- a" a/ V1 b2 T' V# Z
O(H(C)) - {O: 1, H: 1,C:1} - ["O", "(", "H", "(","C", ")", ")"]
1 R! X9 q0 L: k) Z
- Always well-formed input
- Tokens will be one of:
    -Element
    -Number
    - Leftparen "("
    - Rightparen "("
# `  L; Z+ P$ e
private voidadd(Map<String, Integer> map, String key, int val) {
   if(!map.containsKey(key)) { map.put(key, val); }
    else {map.put(key, map.get(key) + val);
}
7 T, W' h% @1 e/ Z" {' S
private booleanisInteger(String s) {
    try {
       Integer.parseInt(s);
    }catch(NumberFormatException e) {
       return false;
   }      
    returntrue;
}
4 J! i6 s7 C1 t+ ]* V) S! \
H20
& X( |2 m3 y4 F4 ]" ~) R* K
i = 0
res: {H: 2}
7 U- V' j6 d3 }7 N
Map<String, Integer>parseEquation(String[] eq) {
   Map<String, Integer> res = new HashMap<String, Integer>();
    Stack<Map<String,Integer>> mapStack = new Stack<Map<String, Integer>>();
   mapStack.push(res);
    for(inti = 0; i < eq.length; ++ i) {
       String cur = eq【i】;
       if(cur.equals("(")) {
           mapStack.push(new HashMap<String, Integer>());
       } else if(cur.equals(")")) {
           int k = 1;
           if(i < eq.length - 1 && isInteger(eq[i + 1])) {
               k = Integer.valueOf(eq[i + 1]);
               ++ i;
           }
           Map<String, Integer> currMap = mapStack.pop();
           Map<String, Integer> prevMap = mapStack.peek();
           for(Map.Entry<String, Integer> entry : currMap.entrySet()) {
               add(prevMap, entry.getKey(), entry.getValue() * k);
           }
       } else if(i < eq.length - 1 && isInteger(eq[i + 1])) {
           add(mapStack.peek(), cur, Integer.parseInt(eq[i + 1]));
           ++ i;
       } else {
           add(mapStack.peek(), cur, 1);
       }
    }
    returnres;
}
% [5 s6 n1 ^+ a, T6 D1 N
Linkedin 加面:
public final class MapPruner
{
  /**
  * Prune a map byremoving entries corresponding to the given paths.
  * Example:
  * input:
  * {
  *   "key1": "bar",
  *   "key2": "baz"
  *   "key3":
  *   {
  *     "key4": "bar"
  *   }
  *  }
  *
  * pathsToPrune:["key2", "key3/key4"]
  *
  * output:
  * {
  *   "key1": "bar",
  *   "key3":
  *   {
  *   }
  * }
  */
* j! p8 O: U. q9 g+ s
//  pathsToPrune = ["" ]
$ e' R/ R0 E- S2 x8 c* i
  private static voidhelper(String[] strs, int i, Map<String, Object> map) { // i = 1; Map:{key4 : bar}
     if(!map.containsKey(strs【i】)) { return; }
      Object val =map.get(strs【i】); // baz; {key4: bar}; bar
      if(i ==strs.length - 1) { map.remove(strs【i】); } // remove baz
      else if(valinstanceof Map) { // true
          helper(strs,i + 1, (Map)val);
      }
  }

  A" w8 x/ V+ M! U7 A5 _( `
  public staticMap<String, Object> pruneByPaths(
    finalMap<String, Object> input,
    finalCollection<String> pathsToPrune)
  {
      if(input == null|| pathsToPrune == null) {
          throw newIllegalArgumentException("Error Msg");
      }
      for(String path: pathsToPrune) { // key2 ; key3/key4
          if(path !=null && !path.equals("")) {
              String[]strs = path.split("/"); // {key2}; [key3, key4]
             if(strs.length > 0) { // 2
                 helper(strs, 0, input);
              }
          }
      }
      return input;
  }

9 Y0 y6 Z& A8 i' e0 x5 s8 w5 F: U& B
5 \  ~9 U% G8 `5 Z0 ^6 c- D- I3 v
5 I) j0 ~( I0 r- U5 t2 ]
FB:
0 G' ^. ?" F& [, g! ~% CFacebook onsite一周,HR说明天约电话,好紧张。面经; w2 @+ v; @* ]9 T
1. Word Break.
' P0 U: E; M/ S% v( M3 v2. Merge K sorted list
  B, [) V  t6 ]0 F$ U3. Word Search(可以斜着走)+ c$ j# |# f, Y1 E! n
. ~( y8 N% @9 B/ {6 R
$ f6 Y% a& x( c) E  ^* y

& x  F) H* |7 D, T. z5 z  M. D0 v
Youtube
1.    视屏推荐的方式; 算法:wildcard match(Leetcode)
2.    一些数据结构概念
给一个String 可以包含数字或者字母 找出里面的是否存在一个substring全是数字而且这个substring表示的数字可以被36整除,并且不能是0。
e.g.: 360ab: True
                  0ab: False
3.    给一堆range(未order有重叠) 然后给一个数 判断这个数是否在range里面
(1,  5)(0,8)(4,6)
9: false
2: true
可以用bitset做
然后衍生出merge interval算法coding,再用bynarysearch找target是否在range中
4.    Pascal Triangle
- v: b: s/ q, Z! u
3 [& F$ a9 }7 R% ~- h
HULU onsite
1.    Recover dictionary order
2.    ATM Database system design (Withdraw,deposit and check balance)
3.    Minimum window
4.    Sliding window for one function only call atmost 3 times in 5 minutes.

) e' S2 ?" h6 k/ S/ w
  d, _% Z4 @! u, T% M* _

本帖被以下淘专辑推荐:

我们始终相信IT会持续改造甚至创新传统行业,我们始终全面看好咱们的CS专业!

2

主题

2

精华

277

积分

高级会员

Rank: 3Rank: 3

积分
277
发表于 12-7-2014 08:54 AM | 显示全部楼层
ym caobosi~~~

18

主题

6

精华

257

积分

高级会员

Rank: 3Rank: 3

积分
257
发表于 12-7-2014 12:06 PM 来自美国米群网手机版 | 显示全部楼层
太赞了!!!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表