Skip to content

Instantly share code, notes, and snippets.

View senthil1216's full-sized avatar

senthil sivasubramanian senthil1216

View GitHub Profile
@senthil1216
senthil1216 / compres_string_patterns
Last active August 29, 2015 14:13
Compress String using Javascript
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]){
#!/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)
#!/usr/local/bin/node
/*
SET a 10
SET b 10
NUMEQUALTO 10 2
NUMEQUALTO 20 0
SET b 30
NUMEQUALTO 10 1
END
@senthil1216
senthil1216 / combinations_phone_number.js
Last active August 29, 2015 14:27
Letter combinations Problem
/**
* @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']};
@senthil1216
senthil1216 / CC_IssuingNetwork.js
Last active August 29, 2015 14:27
Get the Issuing Network based on CC Number
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;
#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]= []
@senthil1216
senthil1216 / persistent_stack.py
Created March 31, 2016 01:14
Persistent Stack
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)
"""
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
"""
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
"""
@senthil1216
senthil1216 / find_max_num_bridges.py
Created April 27, 2016 19:06
Find the maximum number of bridge connections given the random order.
"""
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,