Skip to content

Instantly share code, notes, and snippets.

View sreevidyavutukuru's full-sized avatar

sreevidyavutukuru

View GitHub Profile
def DiceCombinations(n,combinations):
if n == 0:
return combinations
temp = []
for val in range(1,7):
for com in combinations:
temp.append(str(val) + str(com))
n -= 1
list1 = [-2,-1,4,-1,-2,1,5,-3]
def maxsum(list1):
if list1 != None:
max_so_far = list1[0]
max_here = list1[0]
for val in list1[1:]:
max_here = max_here + val
def Binarydepth(self,root):
if root!= None:
return 1 + max(self.Binarydepth(root.left),self.Binarydepth(root.right))
else:
return 0
def PostOrder(self,root):
if root!= None:
print root.val
if root.left!= None:
self.PostOrder(root.left)
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def rightSideView(self, root):
list1= ['a','b',['c','d',['e','f']],'j',['k','l']]
def print_flat(list1,appendStr=''):
if isinstance(list1, str):
print appendStr + ' ' + list1
else:
for i,val in enumerate(list1):
print_flat(val, appendStr + (lambda x: "." if x != "" else "")(appendStr) + str(i))
list1 = [1,2,2,3,4,5,6,9]
def pair_sums(nums,n):
dict_nums = {}
result = []
nums.sort()
for val in nums:
if dict_nums.has_key(val):
dict_nums[val] += 1
else:
dict_nums[val] = 1
'''Given an integer between 0 and 999,999, print an English phrase that describes the integer (eg, “One Thousand, Two Hundred and Thirty Four”).'''
dict_units = {0:'',1:'one',2:'two',3:'three',4:'four',5:'five',
6:'six',7:'seven',8:'eight',9:'nine'}
dict_tens = {0:'',10: 'ten',20:'twenty',30:'thirty',40:'fourty',50:'fifty',60:'sixty',70:'seventy',80:'eighty',90:'ninty'}
steps = {0: '', 1:'thousand', 2 : 'million', 3: 'billion'}
def exp(n):
strn = str(n)
if len(strn) == 3 :
def rotate( nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
if len(nums)==1:
if k ==1:
return nums
list1 = [10,20,3000,10,-1,12000,-10,20,80,300,100,-30,90,10000]
i = 1
j = 1
maxtotal = 0
index_subset = {}
total = []
result = []
for val in list1:
tempmax= maxtotal+val