This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function processData(input) { | |
| var lines = input.split('\n'); | |
| var arr1 = lines[1].split(' ').map(function(x) { return parseInt(x); }); | |
| var arr2 = lines[3].split(' ').map(function(x) { return parseInt(x); }); | |
| var hash = {}; | |
| var length = Math.max(arr1.length, arr2.length); | |
| for (var i=0; i<length; i++) { | |
| if (i < arr1.length) { | |
| hash[arr1[i]] = hash[arr1[i]] ? hash[arr1[i]] + 1 : 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function processData(input) { | |
| var lines = input.split('\n'); | |
| var head = []; | |
| var tail = []; | |
| for (var i=1; i<lines.length; i++) { | |
| var parts = lines[i].split(' '); | |
| var command = parseInt(parts[0]); | |
| var param = parts.length > 1 ? parseInt(parts[1]) : null; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void decode(String S, Node root) | |
| { | |
| if (S.length() == 0) return; | |
| Node pointer = root; | |
| while (pointer.left != null || pointer.right != null) { | |
| int x = Character.getNumericValue(S.charAt(0)); | |
| if (x == 0) { | |
| pointer = pointer.left; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Merge two linked lists | |
| head pointer input could be NULL as well for empty list | |
| Node is defined as | |
| class Node { | |
| int data; | |
| Node next; | |
| } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Get Nth element from the end in a linked list of integers | |
| Number of elements in the list will always be greater than N. | |
| Node is defined as | |
| class Node { | |
| int data; | |
| Node next; | |
| } | |
| */ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int CompareLists(Node headA, Node headB) { | |
| int result = 1; | |
| Node current1 = headA; | |
| Node current2 = headB; | |
| while (current1 != null && current2 != null && current1.data == current2.data) { | |
| current1 = current1.next; | |
| current2 = current2.next; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Node Reverse(Node head) { | |
| if (head == null) { | |
| return head; | |
| } | |
| Node curr = head; | |
| Node prev = head; | |
| Node next = head.next; | |
| while (next != null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Heap implementation. A heap is a fully formed binary tree. | |
| Elements are added to fill the bottom level evenly on left and right. | |
| For max-heaps, parent values must be greater than or equal to their children. | |
| For min-heaps, parent values must be less than or equal to their children. | |
| */ | |
| function add(root, value) { | |
| if (!root) { | |
| root = { val: value }; | |
| } | |
| else { |