Skip to content

Commit 50288e1

Browse files
author
Sagar Paul
committed
---
1 parent 9f3e062 commit 50288e1

9 files changed

+158
-21
lines changed

DSA-problems/01.py

Whitespace-only changes.

DSA-problems/23_Printing Stars in Right Triangle Shape Using while loop.py

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Find nth last Node from the end of the Linkedlist
2+
3+
class Node:
4+
def __init__(self,data):
5+
self.data = data
6+
self.next = None
7+
8+
class Linkedlist:
9+
10+
def __init__(self):
11+
self.head = None
12+
13+
def node_from_end(self):
14+
if self.head is None:
15+
print("The Linkedlist is Empty!")
16+
else:
17+
temp = self.head
18+
samir = self.head
19+
for i in range(n-1):
20+
temp = temp.next
21+
while temp.next is not None:
22+
temp = temp.next
23+
samir = samir.next
24+
print(f"The {n}th node from the end of the linkedlist is {samir.data}")
25+
26+
def add_begine(self,data):
27+
if self.head is None:
28+
self.head = Node(data)
29+
else:
30+
new_node = Node(data)
31+
new_node.next = self.head
32+
self.head = new_node
33+
34+
n = int(input("Type the value of n to find nth last element of this Linkedlist: "))
35+
36+
LL1 = Linkedlist()
37+
LL1.add_begine(15)
38+
LL1.add_begine(14)
39+
LL1.add_begine(13)
40+
LL1.add_begine(12)
41+
LL1.add_begine(11)
42+
LL1.add_begine(10)
43+
LL1.add_begine(9)
44+
LL1.add_begine(8)
45+
LL1.add_begine(7)
46+
LL1.add_begine(6)
47+
LL1.add_begine(5)
48+
LL1.add_begine(4)
49+
LL1.add_begine(3)
50+
LL1.add_begine(2)
51+
LL1.add_begine(1)
52+
53+
print(LL1.node_from_end())
54+
55+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sentence = input("Type a sentence here: ")
2+
s = sentence.lower()
3+
list1 = ["a", "e", "i", "o", "u"]
4+
5+
count = 0
6+
for char in s:
7+
if char in list1:
8+
count = count +1
9+
10+
print(count)
11+
12+
13+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = ["Samir", 1,3,4,3,4,2,4,2,42,11,1,442,1,3844444]
2+
3+
s = [i for i in range(len(a)) if a[i] ==4]
4+
print(s)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def BinerySearch(l,key):
2+
low = 0
3+
high = len(l) - 1
4+
found = False
5+
while low<=high and not found:
6+
mid = (low + high)//2
7+
if key == l[mid]:
8+
found = True
9+
elif key < l[mid]:
10+
high = mid -1
11+
else:
12+
low = mid + 1
13+
if found == True:
14+
print("The value is found.")
15+
else:
16+
print("Value is not found!")
17+
18+
l = [2,3,4,6,64,24,453,33,4242,21]
19+
l.sort()
20+
print(l)
21+
key = int(input("Enter the value of key: "))
22+
BinerySearch(l,key)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def BinarySearch(l,key):
2+
low = 0
3+
high = len(l)-1
4+
found = False
5+
while low<=high and not found:
6+
mid = (low+high)//2
7+
if key == l[mid] :
8+
found = True
9+
elif key < l[mid]:
10+
high = mid -1
11+
elif key > l[mid]:
12+
low = mid +1
13+
if found ==True:
14+
print(f"The key {key} is found!")
15+
else:
16+
print(f"The key {key} is NOT found.")
17+
18+
l = [1,2,4,5,97,324,5464,5555555]
19+
#key = int(input("enter a value within the list: "))
20+
BinarySearch(l,5)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def BinarySearch(l,key):
2+
low = 0
3+
high = len(l)-1
4+
mid = (low+high)//2
5+
found = False
6+
while low<=high and not found:
7+
mid = (low+high)//2
8+
if key == l[mid] :
9+
mid = mid -1
10+
found = True
11+
elif key < l[mid]:
12+
high = mid -1
13+
elif key > l[mid]:
14+
low = mid +1
15+
if found ==True:
16+
print("The key is found!")
17+
print(mid)
18+
else:
19+
print("The key is not found.")
20+
21+
l = [1,2,4,5,97,97,97,97,97,324,5464,5555555]
22+
#key = int(input("enter a value within the list: "))
23+
BinarySearch(l,97)

Roman Number conversion.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def roman_number(num):
2+
if num > 3999:
3+
print("Enter a number below 3999")
4+
else:
5+
value = [1000,900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
6+
symbol = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
7+
roman = ""
8+
i = 0
9+
while num >0:
10+
div = num//value[i]
11+
num = num% value[i]
12+
while div:
13+
roman = roman +symbol[i]
14+
div = div - 1
15+
i = i+1
16+
return roman
17+
18+
num = int(input("Write a number here: \n"))
19+
print(roman_number(num))
20+
21+

0 commit comments

Comments
 (0)