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
Str1 = "aaabbcgfhh" | |
SubStrs = [] | |
SubStrd_Dict = {} | |
for i in range(1,len(Str1)): | |
#SubStrs.append(i) | |
SubStrs = [] | |
for j in range(0,len(Str1)-i): | |
SubStrs.append(Str1[j:j+i]) | |
#print SubStrs | |
SubStrd_Dict[i] = SubStrs |
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
def palindrom(string1): | |
i = 0 | |
j = len(string1) -1 | |
flag = True | |
while i<len(string1)-1 and j >=0: | |
if string1[i] != string1[j]: | |
flag = False | |
break | |
else: |
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
#Kth rank value | |
scores = [10,20,12,3,8] | |
scores.sort() | |
rank_scores = {} | |
for i,val in enumerate(scores): | |
rank_scores[i+1] = val | |
print rank_scores[3] |
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 Solution(object): | |
def lengthOfLongestSubstringTwoDistinct(self, s): | |
""" | |
:type s: str | |
:rtype: int | |
""" | |
sublen = 1 | |
substrings = [] | |
result = {} | |
for i in range(0,len(s)+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
import math | |
def index(list1, n): | |
startIndex = 0 | |
endIndex = len(list1) - 1 | |
while startIndex <= endIndex: | |
mid = startIndex + int(math.floor((endIndex-startIndex)/2)) | |
if list1[mid] == n: | |
print n | |
print mid |
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
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 |
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
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 | |
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 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 : |
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
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 |
OlderNewer