Skip to content

Commit c25a75d

Browse files
authored
set 14 week 3
1 parent 624a1cd commit c25a75d

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

Week 3/SET 14 -Week 3/ques1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class ques1:
2+
3+
def __init__(self):
4+
pass
5+
6+
def twoSum(self, nums, target):
7+
lookup = {}
8+
for i, num in enumerate(nums):
9+
if target - num in lookup:
10+
return (lookup[target - num], i )
11+
lookup[num] = i
12+
13+
arr = [int(x) for x in input().split()]
14+
target = int(input())
15+
obj = ques1()
16+
index1,index2 = obj.twoSum(arr, target)
17+
print (index1 + 1)
18+
print (index2 + 1)
19+
#print("index1=%d, index2=%d" % py_solution().twoSum((10,20,10,40,50,60,70),50))

Week 3/SET 14 -Week 3/ques2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class ques2:
2+
3+
def __init__(self):
4+
pass
5+
6+
def _getString(self):
7+
s = input()
8+
return s
9+
10+
def _printString(self,s):
11+
print(s.upper())
12+
13+
obj = ques2()
14+
s = obj._getString()
15+
obj._printString(s)
16+

Week 3/SET 14 -Week 3/ques3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class ques3():
2+
3+
def __init__(self, l, w):
4+
self.length = l
5+
self.width = w
6+
7+
def rectangle_area(self):
8+
return self.length*self.width
9+
10+
l = int(input())
11+
w = int(input())
12+
obj = ques3(l,w)
13+
print(obj.rectangle_area())

Week 3/SET 14 -Week 3/ques4.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class ques4:
2+
def __init__(self) -> None:
3+
pass
4+
5+
def is_valid_parenthese(self, str1):
6+
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
7+
for parenthese in str1:
8+
if parenthese in pchar:
9+
stack.append(parenthese)
10+
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
11+
return False
12+
return len(stack) == 0
13+
14+
obj = ques4()
15+
s = input()
16+
ans = obj.is_valid_parenthese(s)
17+
print(ans)

Week 3/SET 14 -Week 3/ques5.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class ques5:
2+
def sub_sets(self, sset):
3+
return self.subsetsRecur([], sorted(sset))
4+
5+
def subsetsRecur(self, current, sset):
6+
if sset:
7+
return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(current + [sset[0]], sset[1:])
8+
return [current]
9+
10+
obj = ques5()
11+
arr = [int(x) for x in input().split()]
12+
ans = obj.sub_sets(arr)
13+
print(ans)
14+

0 commit comments

Comments
 (0)