This file contains hidden or 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
''' | |
Recursion Function | |
For 3 disk (Here S= Source, D= Destination,T= Temp) | |
3[S,D,T] | |
/ | \ | |
/ | \ | |
2[S,T,D] 1[S,D,T] 2[T,D,S] | |
/ | \ / | \ | |
/ | \ 1[T,S,D] 1[T,D,S] 1[S,D,T] |
This file contains hidden or 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
#------------------------------------------------------------------------------------------------------------------------- | |
#----------------------------------------------INSERTION SORT------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------------------- | |
def insertion_sort(unsorted_list): | |
i = len(unsorted_list) | |
for num in range(i): | |
for num1 in range(num): | |
if unsorted_list[num] < unsorted_list[num1]: |
This file contains hidden or 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
'''------------------------------------------------------------------------------------------------------------------------- | |
--------------------------------------------------MERGE SORT------------------------------------------------------------- | |
-------------------------------------------------------------------------------------------------------------------------''' | |
def merge_sort(unsorted_list): | |
if len(unsorted_list) == 1: | |
return unsorted_list | |
mid = len(unsorted_list)//2 |
This file contains hidden or 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
#Find question here: https://www.hackerrank.com/challenges/designer-pdf-viewer/problem?h_r=internal-search | |
def designerPdfViewer(h, word): | |
big = 0 | |
l_st = list(set(list(word))) | |
for ch in l_st: | |
val = ord(ch) - 97 | |
if h[val] > big: | |
big = h[val] | |
return len(word) * big |
This file contains hidden or 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
#For question refer : https://www.hackerrank.com/challenges/organizing-containers-of-balls/problem | |
''' logic | |
Suppose there are two container A and B and there are two type of balls in each container (qunatity may varry) | |
Type0 Type 1 | |
A contains [ 1 , 1 ] | |
B contains [ 1 , 1 ] | |
First i am calculating total no of balls of each type. | |
In above example Type0 balls are 2 and Type1 balls are 2 |
This file contains hidden or 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
#For question refer: https://www.hackerrank.com/challenges/strange-code/problem | |
def strangeCounter(t): | |
ti = 1 | |
val = 3 | |
while True: | |
new_ti = ti+val | |
new_val = 2*val | |
if t in range(ti, new_ti): | |
temp = t - ti |
This file contains hidden or 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
# for question refer: https://www.hackerrank.com/challenges/angry-professor/problem | |
def angryProfessor(a, k): | |
count = 0 | |
for stud in a: | |
if stud < 1: | |
count += 1 | |
if count >= k: | |
return "NO" | |
else: | |
return "YES" |
This file contains hidden or 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
#------------Recursive Solution---------------- | |
def BinarySearch(array,target): | |
return BinarySearchHelper(array,target,0, len(array)-1) | |
def BinarySearchHelper(array, target, left, right): | |
middle = (right + left)//2 | |
if left > right: | |
return -1 |
This file contains hidden or 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
print("//////////////////////////////////////////////////////////////////") | |
print("-------------------Fibanocci Series--------------------------------") | |
print("///////////////////////////////////////////////////////////////////\n\n\n") | |
print("-------------------Itertaive Solution------------------------------\n\n") | |
print("-------------------Using List--------------------------------------\n") | |
def fibonacciSeries1(n): | |
series = [0,1] | |
i = 2 |
This file contains hidden or 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
# Uncomment code if you want to see what is actually going inside | |
''' | |
Documentation | |
(I Have numbered the steps in each method if you are not understanding any step refer to the number) | |
a) remove() and remove1() | |
1. Stores the target node | |
2. Stores the previous node to the target node | |
3. Help determining where to append replacement's node after removing target node | |
4. This loop spit out target node and previous node to the target node | |
5. If node becomes None that means target node is not in the tree so retune false |