This file contains 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 compressStringPatterns(inputStr) | |
{ | |
var inp = inputStr.trim().split(''), // convert string to an array | |
prev='', | |
count='', | |
out=''; | |
for(var i = 0; i < inp.length; i++){ | |
// if the prev character is same as the current then incr. the counter | |
if(prev === inp[i]){ |
This file contains 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
#!/usr/bin/python | |
import string | |
import data | |
from toolset import * | |
def problem1(): | |
"""Add all the natural numbers below 1000 that are multiples of 3 or 5.""" | |
return sum(x for x in xrange(1, 1000) if x % 3 == 0 or x % 5 == 0) |
This file contains 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
#!/usr/local/bin/node | |
/* | |
SET a 10 | |
SET b 10 | |
NUMEQUALTO 10 2 | |
NUMEQUALTO 20 0 | |
SET b 30 | |
NUMEQUALTO 10 1 | |
END |
This file contains 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
/** | |
* @param {string} digits | |
* @return {string[]} | |
*/ | |
var letterCombinations = function(digits) { | |
if(!digits){ | |
return []; | |
} | |
var dict = {'2':['a','b','c'],'3':['d','e','f'],'4':['g','h','i'],'5':['j','k','l'],'6':['m','n','o'],'7':['p','q','r','s'],'8':['t','u','v'],'9':['w','x','y','z']}; |
This file contains 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 issuerRange = {}; | |
var issuerLen = {}, | |
maxLen = 0; | |
var add = function(ranges, issuer, lenRanges) { | |
ranges.forEach(function(item) { | |
maxLen = ((maxLen < item.length) ? item.length : maxLen); | |
issuerRange[item] = issuer; | |
}); | |
issuerLen[issuer] = lenRanges; |
This file contains 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
#https://www.hackerrank.com/contests/zenhacks/challenges/pairing | |
N = int(input()) | |
bags = {} | |
for i in range(N): | |
_in = input() | |
sh = _in.split(' ') | |
tup = (str(sh[0]), sh[1], str(sh[2])) | |
if tup not in bags: | |
bags[tup]= [] |
This file contains 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
class Node(object): | |
def __init__(self, x): | |
self.val = x | |
self.next = None | |
self.count = 0 | |
#s1 = push(5, s0) #(5,1) | |
#s2 = push(6, s1) #(6,2)->(5,1) | |
#s3 = push(7, s0) #(7,3)->(6,2)->(5,1) |
This file contains 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
""" | |
Given a string of 0s, 1s and ?s (wildcards), generate all 0-1 strings that match this pattern, e.g. | |
1?00?101 -> [10000101, 10001101, 11000101, 11001101]. You can generate strings in any order that suit you. | |
""" | |
class Tree(object): | |
def __init__(self, x): | |
self.val = x | |
self.left = None |
This file contains 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
""" | |
Given an input array and target sum, find all possible ways the elements of the array can be added upto get target | |
sub_set_sum([10, 7, 5, 18, 12, 20, 15], 35) => | |
([15, 22, 14, 26, 32, 9, 16, 8], 53) => | |
8 9 14 22 | |
8 14 15 16 | |
15 16 22 | |
http://ideone.com/ZpDAXJ | |
""" |
This file contains 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
""" | |
A B C D | |
-river- | |
B C A D | |
Find the maximum number of bridge connections given the random order. | |
top = {A : 0, | |
B : 1, | |
C : 2, |
OlderNewer