# AICS interview
## K8S 與 K3S 差異:
如面試的時候所討論, K3S 是相對輕量的 K8S solution, 整包安裝完畢只需要 40MB, 對 node 的需求也較小, 比較如下:
* Kubeadmn:
2 GB or more of RAM
2 CPUs or more
* K3s:
512 MB or more of RAM
1 CPU or more
另外在 K3s 架構裡面 Master 也可以 deploy pod 上去, 其他的 solutions 除非另外調整, 一般不會 deploy pod 到 master node.這代表在 K3s 架構下可以更省硬體資源, 對於 dev 環境在地端的服務場景, 在 cost 的考量下, K3s 算是不錯的 solution.不過, K3s 的 Master node 只能有一個, 所以當 Master node 掛掉的時候, 整個 cluster 都會死掉.
## Linked list swap function:
``` javascript
class Node {
constructor(value, next = null) {
this.next = next;
this.value = value;
}
}
const node1 = new Node(1);
const node2 = new Node(2);
const node3 = new Node(3);
const node4 = new Node(4);
const node5 = new Node(5);
node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;
function printList(node) {
console.log(node.value);
if (node.next) {
printList(node.next);
} else {
return;
}
}
console.log('original linked list:');
printList(node1);
var swapPairs = function(head) {
// 處理例外 case
if (!head) {
// 全空
return null;
}
if (!head.next) {
// 只有 root
return head;
}
// 暫時記一個從第二個 node 始的 temp node
const tempNode = head.next;
// 記下第二個數字
const newRootValue = head.next.value;
// 把第二個數字拿掉
head.next = tempNode.next;
// 把第二個數字加到第一個前面
// 得到第一個 跟 第二個數字交換的 list
const afterSwapNode = {
value: newRootValue,
next: head
};
// 因為一次交換兩個, 所以下一個從第三個開始
if (afterSwapNode.next.next !== null && afterSwapNode.next.next.next !== null ) {
afterSwapNode.next.next = swapPairs(afterSwapNode.next.next);
}
return afterSwapNode;
};
console.log('new linked list:');
printList(swapPairs(node1));
```
執行結果
