Skip to content

Commit c37e4e9

Browse files
committed
Adding all previously written code
0 parents  commit c37e4e9

File tree

47 files changed

+875
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+875
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
t = int(input())
2+
for ts in range(t):
3+
n = int(input())
4+
if n == 1: print(0)
5+
elif n == 2: print(1)
6+
elif n == 3: print(2)
7+
elif n % 2 == 0: print(2)
8+
else: print(3)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
T = int(input())
2+
for tc in range(T):
3+
n = int(input())
4+
st = ""
5+
for x in range(2, n + 1):
6+
st += str(x)
7+
st += str(" ")
8+
st += "1"
9+
print(st)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import math
2+
3+
T = int(input())
4+
for tc in range(T):
5+
n = int(input())
6+
chosennumbers = list(map(int, input().split()))
7+
mimim = math.inf
8+
flag = True
9+
if len(chosennumbers) == 1:
10+
print("1")
11+
elif len(chosennumbers) == 2:
12+
if chosennumbers[0] == chosennumbers[1]: print("-1")
13+
elif chosennumbers[0] < chosennumbers[1]: print("1")
14+
else: print("2")
15+
else:
16+
chosennumberssorted = chosennumbers.copy()
17+
chosennumberssorted.sort()
18+
while len(chosennumberssorted) > 1:
19+
if chosennumberssorted[0] == chosennumberssorted[1]:
20+
flag = False
21+
number = chosennumberssorted[0]
22+
while len(chosennumberssorted) > 0 and chosennumberssorted[0] == number:
23+
chosennumberssorted.pop(0)
24+
else:
25+
flag = True
26+
mimim = chosennumberssorted[0]
27+
print(str(chosennumbers.index(chosennumberssorted[0]) + 1))
28+
break
29+
if not flag and len(chosennumberssorted) == 1:
30+
print(str(chosennumbers.index(chosennumberssorted[0]) + 1))
31+
elif not flag:
32+
print("-1")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
T = int(input())
2+
for tc in range(T):
3+
n = int(input())
4+
sequence = list(map(int, input().split()))
5+
appearen = []
6+
for i in range(n):
7+
appearen.append(sequence.count(sequence[i]))
8+
9+
mimumappear = min(appearen)
10+
if mimumappear == 1:
11+
if appearen[0] == 1 or appearen[n - 1] == 1: print(1)
12+
else:
13+
if appearen[0] == 2 and appearen[n - 1] == 2:
14+
print(1)
15+
else:
16+
print(2)
17+
elif appearen[0] == n: print(0)
18+
else:
19+
if appearen[0] == mimumappear and appearen[n - 1] == mimumappear:
20+
print(str(mimumappear - 1))
21+
elif appearen[0] == mimumappear or appearen[n - 1] == mimumappear:
22+
print(mimumappear)
23+
else:
24+
if appearen[0] == mimumappear + 1 and appearen[n - 1] == mimumappear + 1:
25+
print(mimumappear)
26+
else:
27+
print(str(mimumappear + 1))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import math
2+
3+
T = int(input())
4+
for tc in range(T):
5+
n = int(input())
6+
sequence = list(map(int, input().split()))
7+
minsteps = math.inf
8+
for i in range(n):
9+
select = sequence[i]
10+
j = 0
11+
segment = 0
12+
countsteps = 0
13+
while len(sequence) > 0 and j < len(sequence):
14+
if sequence[j] == select:
15+
if segment == 0: j = j + 1
16+
else:
17+
k = 1
18+
while k < segment + 1 and j - segment < len(sequence):
19+
sequence.pop(j - segment)
20+
countsteps = countsteps + 1
21+
segment = 0
22+
j = j - k - 1
23+
else:
24+
segment = segment + 1
25+
j = j + 1
26+
if segment != 0:
27+
k = 1
28+
while k < segment + 1 and j - segment < len(sequence):
29+
sequence.pop(j - segment)
30+
countsteps = countsteps + 1
31+
segment = 0
32+
j = j - k - 1
33+
minsteps = min(minsteps, countsteps)
34+
print(minsteps)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
T = int(input())
2+
for tc in range(T):
3+
n = int(input())
4+
seq = list(map(int, input().split()))
5+
ans = []
6+
for i in range(n // 2):
7+
ans.append(seq[i])
8+
ans.append(seq[n - i - 1])
9+
if len(seq) % 2 != 0:
10+
ans.append(seq[len(seq) // 2])
11+
print(*ans)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
T = int(input())
2+
for tc in range(T):
3+
n = int(input())
4+
st = input()
5+
if st[0:4] == "2020" or st[n - 4:n] == "2020":
6+
print("YES")
7+
elif n >= 4 and st[0] == "2" and st[n - 3:n] == "020":
8+
print("YES")
9+
elif n >= 4 and st[0:2] == "20" and st[n - 2:n] == "20":
10+
print("YES")
11+
elif n >= 4 and st[0:3] == "202" and st[n - 1] == "0":
12+
print("YES")
13+
else:
14+
print("NO")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
T = int(input())
2+
for tc in range(T):
3+
n = int(input())
4+
if len(str(n)) == 1:
5+
print(n)
6+
elif n > 45:
7+
print(-1)
8+
else:
9+
minim = -1
10+
digits = [0, 0, 0, 0, 0, 0, 0, 0, 9]
11+
i = 7
12+
while True:
13+
if digits[i] < i + 1:
14+
digits[i] += 1
15+
else:
16+
i -= 1
17+
digits[i] += 1
18+
if sum(digits) == n:
19+
minim = int(''.join(map(str, digits)))
20+
break
21+
print(minim)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# T = int(input())
2+
# for tc in range(T):
3+
# n = int(input())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# # import itertools
2+
#
3+
# T = int(input())
4+
# for tc in range(T):
5+
# n = int(input())
6+
# seq = list(map(int, input().split()))
7+
# count = 0
8+
# seq.sort()
9+
# for i in range(n):
10+
# for j in range(i + 1, n):
11+
# if seq[j] - seq[i] > 2:
12+
# break
13+
# for k in range(j + 1, n):
14+
# if seq[k] - seq[i] > 2:
15+
# break
16+
# else:
17+
# count += 1
18+
# # comb = itertools.combinations(seq, 3)
19+
# # for c in comb:
20+
# # print(c)
21+
# # if max(c) - min(c) <= 2:
22+
# # count += 1
23+
# print(count)

0 commit comments

Comments
 (0)