linkedin 电面准备

 (1) 先確 認問題,與 interviewer 討論 問題.
          (2) 說明可能的 input & output 的輸入 ,有沒有 你想的到的任何 所有的輸入 、出的例外
          (3) 給出可能的 soution. 然後interviewer 會選 他制的好的solution實作
          (4) start coding

Corner case check还有invalid 输入的时候返回啥最好。

 

 tech questions 1). process/thread 区别 2) java 中stack/heap 的区别

1) The main difference between heap and stack is that stack memory is used to store local variables and function call while heap memory is used to store objects in Java. No matter, where the object is created in code e.g. as a member variable, local variable or class variable,  they are always created inside heap space in Java.
 3) If there is no memory left in the stack for storing function call or local variable, JVM will throw java.lang.StackOverFlowError, while if there is no more heap space for creating an object, JVM will throw java.lang.OutOfMemoryError: 4) If you are using Recursion, on which method calls itself, You can quickly fill up stack memory. Another difference between stack and heap is that size of stack memory is a lot lesser than the size of  heap memory in Java.

    

尤其这个返回值的讨论我对他的意见表示不苟同,但是想想特么算了找工作要紧只能说always good to learn new idea..

 

What is the difference between HashSet and TreeSet implementation of a Set ?

 1. TreeSet guarantees arrangement of elements according to their natural ordering always, HashSet doesn't guarantee. 
2. TreeSet implements Red-Black Trees(spl Binary Tree, no arrays), while HashSet uses arrays and hashing mechanism. 
3. For put, get, contains(), remove: HashSet - O(c), TreeSet - O(log n).

你趁还有时间赶紧讲讲系统架构吧。”我就试着把load balancer, master-slave这些东西开始讲

这个topk是一个高频题。要考虑到系统的规模,结果的实时性。基本上答题的思路是设计一个kafka+samza - 因为是面linkedin。

kafka是肯定要提到的,还有就是怎么存数据,怎么aggregate。

 

提前说了我的主语言是 JAVA,上来问了两个 JAVA 的问题:
1. Thread 和 Process 有什么区别?什么时候用 Thread 什么时候用 Process?

  1. Ans) Differences between threads and processes are:-

1. Threads share the address space of the process that  created it; processes have their own address.

2. Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.

3. Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes.

4. Threads have almost no overhead; processes have considerable overhead.

5. New threads are easily created; new processes require duplication of the parent process.

6. Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.

7. Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process; changes to the parent process do not affect child processes.

 

In general (and it varies by operating system):

  • Threads are usually lighter-weight than processes
  • Processes provide better isolation between actions
  • Threads provide simpler data sharing and coordination within the process

when to use process over thread:

OS Resource Limits & Governance

  • If the process, using a single thread, is already using all of the available address space (e.g. for 32bit apps on Windows 2GB), you might need to distribute work amongst processes.

  • Limiting the use of resources (CPU, memory, etc.) is typically only possible on a per process basis (for example on Windows you could create "job" objects, which require a separate process).

Security Considerations

  • You can run different processes using different accounts (i.e. "users"), thus providing better isolation between them.

Compatibility Issues

  • Support multiple/different Java versions: Using differnt processes you can use different Java versions for your application parts (if required by 3rd party libraries).

Location Transparency

  • You could (potentially) distribute your application over multiple physical machines, thus further increasing scalability and/or robustness of the application (see @Qwe's answer for more Details / the original idea).

垃圾处理机制:

https://dzone.com/articles/jvm-and-garbage-collection

http://www.importnew.com/1993.html

 

2. 为什么要有 Exception?为什么遇到问题要 throw Exception 而不是返回特殊值(比如 -1)?

  • Runtime Exceptions: They usually happen due to programmers fault. For example, if an ArithmeticException of division by zero occurs or an ArrayIndexOutOfBoundsExceptionoccurs, it is because we are not careful enough in our coding. They happen usually because some errors in our program logic. So, they must be cleared before our program enters into production mode. They are unchecked in the sense that, our program must fail when it occurs, so that we programmers can resolve it at the time of development and testing itself.

  • Errors: Errors are situations from which usually the program cannot recover. For example, if a StackOverflowError occurs, our program cannot do much, such as increase the size of program's function calling stack. Or if an OutOfMemoryError occurs, we cannot do much to increase the amount of RAM available to our program. In such cases, it is better to exit the program. That is why

posted @ 2017-11-30 06:54  apanda009  阅读(256)  评论(0编辑  收藏  举报