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+
def Linear_Search(alist, item):
6+
for i in range(len(alist)):
7+
if alist[i] == item:
8+
return True
9+
return False
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+
def bianry_search(alist, item):
9+
"""Binary Search Algorithm"""
10+
first = 0
11+
last = len(alist)-1
12+
found = False
13+
while first <= last and not found:
14+
mid = (first+last)//2
15+
if alist[mid] == item:
16+
found = True
17+
else:
18+
if item < alist[mid]:
19+
last = mid-1
20+
else:
21+
first = mid+1
22+
return found
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+
def swap_case(s):
10+
a = ""
11+
for word in s:
12+
if word.isupper() == True:
13+
a += (word.lower())
14+
else:
15+
a += (word.upper())
16+
return a
17+
18+
19+
s = "Www.HackerRank.com"
20+
21+
print(swap_case(s))

0 commit comments

Comments
 (0)