Skip to content

Instantly share code, notes, and snippets.

View wataruoguchi's full-sized avatar
🦥
Curiosity Driven

Wataru Oguchi wataruoguchi

🦥
Curiosity Driven
View GitHub Profile
@wataruoguchi
wataruoguchi / PrintBTinVerticalOrder.js
Created July 27, 2019 05:03
Print a Binary Tree in Vertical Order | Set 1
// https://www.geeksforgeeks.org/print-binary-tree-vertical-order/
class Node {
constructor(val, left, right) {
this.val = val;
this.left = left;
this.right = right;
}
}
function verticalOrder(root, arr) {
@wataruoguchi
wataruoguchi / SerializeDeserialize.js
Created July 27, 2019 03:56
Serialize and Deserialize a Binary Tree
// https://www.geeksforgeeks.org/serialize-deserialize-binary-tree/
class Node {
constructor(val, left, right) {
this.val = val;
this.left = left;
this.right = right;
}
}
function inorder(root, arr) {
@wataruoguchi
wataruoguchi / LowestCommonAncestorInABinaryTree.js
Created July 26, 2019 07:41
Lowest Common Ancestor in a Binary Tree
// https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/
class Node {
constructor(val, left, right) {
this.val = val;
this.left = left;
this.right = right;
};
}
// https://www.geeksforgeeks.org/convert-a-given-binary-tree-to-doubly-linked-list-set-4/
class Node {
constructor(val, left, right) {
this.val = val;
this.left = left;
this.right = right;
};
}
@wataruoguchi
wataruoguchi / code.js
Created July 26, 2019 05:42
Implementing a Complete Binary Heap in JavaScript: The Priority Queue
// https://codeburst.io/implementing-a-complete-binary-heap-in-javascript-the-priority-queue-7d85bd256ecf
// Linked list
class Node {
constructor(val, priority) {
this.val = val;
this.priority = priority;
this.next = null;
}
}
function buildTree(arr, root, idx, n) {
const leftIdx = 2 * idx + 1;
const rightIdx = 2 * idx + 2;
if (idx < n) {
root = {
val: arr[idx],
left: buildTree(arr, root ? root.left : null, leftIdx, n),
right: buildTree(arr, root ? root.right : null, rightIdx, n),
};
}
function serialize(root) {
if (!root) {
return 'X,'
}
const left = serialize(root.left);
const right = serialize(root.right);
return root.val += `,${left}${right}`;
}
function deserialize(str) {
{
"FunctionName": "transcode-video",
"FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:transcode-video",
"Runtime": "nodejs10.x",
"Role": "arn:aws:iam::000000000000:role/lambda-s3-execution-role",
"Handler": "index.handler",
"CodeSize": 5665493,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
// package.json
{
...
"scripts": {
...
"deploy": "aws lambda update-function-code --function-name arn:aws:lambda:us-east-1:000000000000:function:transcode-video --zip-file fileb://Lambda-Deployment.zip",
"predeploy": "rm Lambda-Deployment.zip > /dev/null && npm prune --production && zip -r Lambda-Deployment.zip * -x *.zip *.log",
"postdeploy": "npm i --offline"
}
...
{
"FunctionName": "transcode-video",
"FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:transcode-video",
"Runtime": "nodejs10.x",
"Role": "arn:aws:iam::000000000000:role/lambda-s3-execution-role",
"Handler": "index.handler",
"CodeSize": 26312199,
"Description": "",
"Timeout": 3,
"MemorySize": 128,