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 hash = {}; | |
| for (var i=0; i<input.length; i++) { | |
| var ch = input.charCodeAt(i); | |
| if (ch >= 65 && ch <= 90) { | |
| ch += 32; // lowercase | |
| } | |
| // Only consider alphabet. |
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) { | |
| //Enter your code here | |
| var lines = input.split('\n'); | |
| var stack = []; | |
| var max = 0; | |
| for (var i=1; i<lines.length; i++) { | |
| var parts = lines[i].split(' ').map(function(x) { return parseInt(x); }); | |
| var command = parts[0]; | |
| var value = parts.length > 1 ? 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
| // Find the smallest decreasing number in an array, before increasing values. | |
| var findMinBeforeIncrease = function(arr) { | |
| var result = null; | |
| var current = 0; | |
| for (var i=1; i<arr.length; i++) { | |
| if (arr[i] < arr[i-1]) { | |
| current = arr[i]; | |
| } | |
| else { |
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
| var longestUnique = function(s) { | |
| var result = ''; | |
| var hash = {}; | |
| var current = ''; | |
| for (var i=0; i<s.length; i++) { | |
| hash[s[i]] = hash[s[i]] ? hash[s[i]] + 1 : 1; | |
| if (hash[s[i]] > 1) { | |
| // Terminate string here. |
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
| for (var counter = 0; counter <= 100; counter++) { | |
| var notPrime = false; | |
| for (var i = 2; i <= counter; i++) { | |
| if (counter % i === 0 && i !== counter) { | |
| notPrime = true; | |
| } | |
| } | |
| if (notPrime === false) { |
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
| var addNode = function(val, head) { | |
| var node = { val: val, children: [] }; | |
| if (head) { | |
| head.children.push(node); | |
| } | |
| return node; | |
| } |
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
| var dollartize = function(num) { | |
| var result = ''; | |
| var numStr = num + ''; | |
| var count = 0; | |
| for (var i=numStr.length - 1; i>=0; i--) { | |
| if (count++ % 3 === 0) { | |
| result = ',' + result; | |
| } |
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
| package main | |
| import "fmt" | |
| func fibn(n int) int { | |
| result := 0 | |
| if n == 0 { | |
| result = 0 | |
| } else if n == 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
| var insert = function(value, root) { | |
| if (!root) { | |
| // Create a new root. | |
| root = { val: value }; | |
| } | |
| else { | |
| var current = root; | |
| while (current) { | |
| if (value < current.val) { | |
| if (!current.left) { |