-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def minRows (hs): | ||
rowMins = [-1 for i in range (len (hs))] | ||
rowCount = 0 | ||
for num in hs: | ||
for i in range (len (rowMins)): | ||
if (rowMins[i] == -1): | ||
rowMins[i] = num | ||
rowCount +=1 | ||
break | ||
elif (rowMins[i] > num): | ||
rowMins[i] = num | ||
break | ||
return rowCount |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
''' | ||
Following function checks if a word is a palindrome | ||
Takes in user input | ||
''' | ||
def isPalindromic (word): | ||
for i in range (0, len (word) // 2): | ||
if (word[i].lower() != word[len(word) - 1 - i].lower()): | ||
return False | ||
return True | ||
word = input("Enter a word you want to check: ") | ||
|
||
if (isPalindromic (word)): | ||
print ("{} is a planindrome!".format(word)) | ||
else: | ||
print ("{} is not a palindrome".format(word)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
''' | ||
following code prints out all the possilble alphabetic combination for string length of n | ||
characters are limited to a-z for now | ||
''' | ||
|
||
def print_all_combs (n): | ||
def print_combs_recur (str): | ||
if (len (str) == n): | ||
print (str) | ||
else: | ||
for i in range (0, 26): | ||
print_combs_recur (str + chr (ord ('a') + i)) | ||
print_combs_recur ("") | ||
|
||
# print all the possible 4 letter words using [a-z] | ||
print_all_combs (4) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
''' | ||
Following code checks whether or not | ||
two strings are permutaitons of one another | ||
Not case sensetive | ||
''' | ||
|
||
def arePerms (str1, str2): | ||
if (len (str1) != len (str2)): | ||
return False | ||
# Create a histogram of str1 and cancel it out using str2 | ||
# If there are any left overs, not permuations of each other | ||
histogram = [0 for i in range (0, 26)] | ||
|
||
for i in range (0, len (str1)): | ||
# creating a histogram for how many times each letter in str1 appears | ||
# subtracting 97 to normalize characters by taking the value of 'a' on each character | ||
# decrease each count of str2 | ||
histogram[ord(str1[i].lower()) - 97] +=1 | ||
histogram[ord(str2[i].lower()) - 97] -= 1 | ||
|
||
#check if there are any leftovers | ||
for count in histogram: | ||
if count != 0: | ||
return False | ||
return True | ||
|
||
#Tests | ||
print(arePerms ("abc", "cba")) #True | ||
print(arePerms ("lol", "llz")) #False | ||
print(arePerms ("ABcd", "cBaD")) #True | ||
print(arePerms ("", "")) #True | ||
print(arePerms ("oofdf", "oofd")) #False |