Skip to content

Commit 01c355d

Browse files
committed
Day13
1 parent eeff30d commit 01c355d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

Day13/q46.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Implement the Linear search
2+
3+
__author__="Mahtab Alam"
4+
5+
defLinear_Search(alist, item):
6+
foriinrange(len(alist)):
7+
ifalist[i] ==item:
8+
returnTrue
9+
returnFalse
10+
11+
12+
l= [23, 4, 5, 1, 2, 3]
13+
14+
print(Linear_Search(l, 10))

Day13/q47.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# implemet Binary Search Algorithm
2+
3+
# Note For binary serch Array must be sorted
4+
5+
__author__="Mahtab Alam"
6+
7+
8+
defbianry_search(alist, item):
9+
"""Binary Search Algorithm"""
10+
first=0
11+
last=len(alist)-1
12+
found=False
13+
whilefirst<=lastandnotfound:
14+
mid= (first+last)//2
15+
ifalist[mid] ==item:
16+
found=True
17+
else:
18+
ifitem<alist[mid]:
19+
last=mid-1
20+
else:
21+
first=mid+1
22+
returnfound
23+
24+
25+
print(bianry_search([4, 5, 6, 7, 8, 9], 4))

Day13/q48.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
# Problem Link https://www.hackerrank.com/challenges/swap-case/problem
4+
5+
6+
__author__="Mahtab Alam"
7+
8+
9+
defswap_case(s):
10+
a=""
11+
forwordins:
12+
ifword.isupper() ==True:
13+
a+= (word.lower())
14+
else:
15+
a+= (word.upper())
16+
returna
17+
18+
19+
s="Www.HackerRank.com"
20+
21+
print(swap_case(s))

0 commit comments

Comments
 (0)
close