1. OOP 的特性是什麼?
- Packing - information hiding
- Inheritance - for reuse
- Polymorphism - flexibility
多型可以說是,將相同訊息傳遞給不同的物件,進而引發出不同的反應。
2. Difference between java 7 and java 8
- 有 lambda 函數
3. Design pattern in java
singleton builder observer
4. What is lambda function and write java code where you can use it
允許可以直接 pass 一個 lambda function 當成參數進去函數裡面。因此對於有些只需要用到一次的 function 來說,就不需要再另外個 class 給它。(lambda function 跟 anonymous function 的差別?)
來自彥志補充:一個 syntex sugar 去代替 anonymous function
e.g. Queue
5. To implement a tic-tac-toe game
6. how to find the error in a log file using command in Linux
grep
7. how to create a file or a directory in Linux3
touch, mkdir
8. What are the benefits of neural networks
9. how to design the primary key for the employees in the company if not given the ssn, only have the name and the address
如果姓名跟地址有唯一性,可以直接用
10. how to process the data given lots of data
11. design a class (given a random(a,b) generate a random number from a to b inclusively)
class randomNumberGenerator { int number, a, b; public randomNUmberGenerator(int a, int b) { this.a = a; this.b = b; } number = Math.floor(Math.random() (b + 1) - Math.random() (a + 1)); }
12. design poker game. take five random cards from a deck of poker cards; shuffle 52 cards and take first five poker cards
class card { String type; int num; public Card(String type, int num) { this.type = type; this.num = num; } }
class game { card[] cards = new card[52]; String[] types = new String[]{"a", "b", "c", "d"}; int count = 0; for (String s : types) { for (int i = 1; i < 14; i++) { cards[count] = new card(s, i); count++; } } shuffle();
public List<card> takeFirstFive() {
List<card> res = new ArrayList<card>();
for (int i = 0; i < 5; i++) {
res.add(list.get(i));
}
return res;
}
public void shuffle() {
for (int i = 0; i < cards.length; i++) {
int randomNum = Math.floor(Math.random * 52);
card temp = cards[i];
cards[i] = cards[randomNum];
cards[randomNum] = temp;
}
}
}
13. randomly generate ice cream flavors, 每种flavor的概率不一样
14. two sum
class Solution { public boolean twoSum(int[] array, int target) { if (array == null || array.length == 0) { return false; }
Arrays.sort(array);
int start = 0, end = array[array.length - 1];
while (end > start) {
if (array[start] + array[end] == target) {
return true;
} else if (array[start] + array[end] > target) {
end--;
} else {
start++;
}
}
return false;
}
}
15. 在linked list里找倒数第k个node
1 -> 2 -> 3 -> 4 找倒數第二個
dummy -> 1 -> 2 -> 3 -> 4 slow = dummy, fast = dummy.next.next; while (fast != null) { slow = slow.next; fast = fast.next; } return slow;
16. 一個 array 裡找最小的兩個數
- 有沒有重複
- 有沒有 sort 過
int min = min2 = Integer.MAX_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] < min) { int temp = min; min = array[i]; min2 = temp; } else if (array[i] > min && array[i] < min2) { min2 = array[i]; } }
17. heapify
- 從上往下 heapify
從下往上 heapify
2 3 4 1 5
nums[]
cur = k, left = 2k + 1, right = 2k + 2; heapify(int[] a) { for (int i = a.length / 2; i >= 0; i--) { helper(a, i); } }
public void helper(int[] a, int idx) { if (idx >= a.length) { return; }
int idx_left = 2 * idx + 1 >= a.length? Integer.MIN_VALUE : 2 * idx + 1;
int idx_right = 2 * idx + 2 >= a.length? Integer.MIN_VALUE : 2 * idx + 2;
if (a[idx] > a[idx_left] && a[idx] < a[idx_right]) {
swap(a, idx, idx_right);
helper(a, idx_right);
} else if (a[idx] > a[idx_right] && a[idx] < a[idx_left]) {
swap(a, idx, idx_left);
helper(a, idx_left);
} else if (a[idx] > a[idx_right] && a[idx] > a[idx_left]) {
if (a[idx_right] > a[idx_left]) {
swap(a, idx, idx_left);
helper(a, idx_left);
} else {
swap(a, idx, idx_right);
helper(a, idx_right);
}
}
}
public void swap(int[] a, int parent, int child) { int temp = a[parent]; a[parent] = a[child]; a[child] = temp; }
18. heap sort 的時間複雜度
nlogn
19. unsorted vector 找最小的
20. unsorted linked-list 找一個數,問複雜度(比 O(n) 更快)
21. 在很大的 string 裡找可能的電話號碼
maybe KMP algorithm?
22. C++ 跟 Java 有什麼區別;編譯生成的 class file 有什麼不同;有什麼程式只能用 C++ 寫不能用 Java
23. SQL 基本的知識要了解一下
24. 怎麼把 string 轉成整數 (C++ 的 atoi function)
25. java 裡 public, protected, private
26. string 跟 stringbuilder 的差別
27. java 跟 python 的差別
28. 寫一個 sql 跟 merge sort
29. http 跟 tcp 的區別
30. 瀏覽器輸入網址之後發生了什麼 (TCP/IP)
=== linux 指令: 進入 directory: cd 列出當前 dir 的 files: ls 查看詳細訊息: ls -I (need to be checked) 修改文件權限: chmod