Skip to content

Commit bfd785c

Browse files
committed
Problems from GFG
1 parent b3be2a0 commit bfd785c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Adding_Ones.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
inp1 = [int(x) for x in input().split()]
2+
inp2 = [int(x) for x in input().split()]
3+
l1 = inp1[0]
4+
l2 = inp1[1]
5+
final_arr = inp2[:l2]
6+
arr = []
7+
count = 0
8+
9+
print(final_arr)
10+
for x in range(l1):
11+
arr.append(0)
12+
13+
for y in final_arr:
14+
for x in range(l1):
15+
if y >= arr[x]:
16+
arr[x] +=1
17+
print(arr)

game_problem.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Problem Link = https://www.hackerrank.com/challenges/an-interesting-game-1/problem
3+
"""
4+
5+
def gamingArray_optimized(arr):
6+
count=0
7+
m=0
8+
for i in arr:
9+
if i>m:
10+
m=i
11+
count+=1
12+
if count%2==0:
13+
print("ANDY")
14+
else:
15+
print("BOB")
16+
17+
18+
def gamingArray(arr): ### time exceeding for 4 cases , optimizationx please
19+
c = -1
20+
while(1):
21+
if len(arr) == 0:
22+
break
23+
i = arr.index(max(arr))
24+
del arr[i:]
25+
c +=1
26+
27+
if c % 2==0:
28+
print("BOB")
29+
else:
30+
print("ANDY")
31+
32+
33+
t =[7 ,4 ,6 ,5 ,9] ## ANDY
34+
s = [1, 3, 5, 7, 9] ## BOB
35+
e = [5 ,2 ,6 ,3 ,4] ## ANDY
36+
d = [3,1] ## BOB
37+
gamingArray(t)
38+
gamingArray(s)
39+
gamingArray(e)
40+
gamingArray(d)
41+
gamingArray_optimized(t)
42+
gamingArray_optimized(s)
43+
gamingArray_optimized(e)
44+
gamingArray_optimized(d)

timing_problems.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def time(s):
2+
date = s.split(":")
3+
print(date)
4+
if date[2][2:] == "AM":
5+
if date[0] == "12":
6+
return ("00:{}:{}".format(date[1],date[2][:2]))
7+
else:
8+
return ("{}:{}:{}".format(date[0],date[1],date[2][:2]))
9+
if date[2][2:] == "PM":
10+
if date[0] == "12":
11+
return ("{}:{}:{}".format(date[0],date[1],date[2][:2]))
12+
else:
13+
return ("{}:{}:{}".format((12 + int(date[0])),date[1],date[2][:2]))
14+
15+
s = time("07:05:45PM")
16+
print(s)

0 commit comments

Comments
 (0)