Skip to content

Commit 2d5d46f

Browse files
committed
Add BFS and CC Long Challenge Solutions
1 parent 8f233c1 commit 2d5d46f

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
for _ in range(int(input())):
2+
n, k = map(int, input().split())
3+
inp = list(map(int, input().split()))
4+
if n == 1:
5+
print(int((inp[0] / k) + 1))
6+
continue
7+
total = 0
8+
day = 0
9+
dayFound = 0
10+
for i in range(n):
11+
day += 1
12+
if(inp[i] + total < k):
13+
print(int(day))
14+
dayFound = 1
15+
break
16+
total = (inp[i] + total) - k
17+
if not dayFound:
18+
day += total / k
19+
print(int(day + 1))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
for _ in range(int(input())):
2+
N, K, X, Y = map(int, input().split())
3+
z = X
4+
f = 0
5+
while True:
6+
X = (X + K) % N
7+
if Y == X:
8+
f = 1
9+
break
10+
elif X == z:
11+
break
12+
if f == 1:
13+
print("YES")
14+
else:
15+
print("NO")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def power(n):
2+
return n != 0 and ((n & (n-1)) == 0)
3+
4+
def main():
5+
for i in range(int(input())):
6+
n = int(input())
7+
if n == 1:
8+
print(1)
9+
continue
10+
elif n == 3:
11+
print("1 3 2")
12+
continue
13+
elif n == 5:
14+
print("2 3 1 5 4")
15+
continue
16+
elif(power(n)):
17+
print(-1)
18+
continue
19+
else:
20+
print("2 3 1 5 4")
21+
i = 6
22+
while(i <= n):
23+
if power(i):
24+
print(str(i+1) + " " + str(i), end=" ")
25+
i += 2
26+
else:
27+
print(i)
28+
i += 1
29+
print("\n")
30+
31+
main()

DataStructures/Graph/bfs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def bfs(g,N):
2+
queue = []
3+
visited = [False] * (N)
4+
bfs = []
5+
queue.append(0)
6+
visited[0] = True
7+
while queue:
8+
cur = queue.pop(0)
9+
bfs.append(cur)
10+
for neighbour in g[cur]:
11+
if not visited[neighbour]:
12+
queue.append(neighbour)
13+
visited[neighbour] = True
14+
return bfs

0 commit comments

Comments
 (0)