From dac7cc620083cda1bc09973f972ec6403c1bc236 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:30:11 +0530 Subject: [PATCH 01/45] Create DOA_01.py --- December 01/DOA_01.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 December 01/DOA_01.py diff --git a/December 01/DOA_01.py b/December 01/DOA_01.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/December 01/DOA_01.py @@ -0,0 +1 @@ + From 69990dab9c94bbd36ecc4cc10ba9e25864098925 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:43:10 +0530 Subject: [PATCH 02/45] Update DOA_01.py --- December 01/DOA_01.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/December 01/DOA_01.py b/December 01/DOA_01.py index 8b13789..1ee1374 100644 --- a/December 01/DOA_01.py +++ b/December 01/DOA_01.py @@ -1 +1,9 @@ - +n = int(input()) +runs = [int(i) for i in input().split()] +maxi, t_runs = 0, 0 +for k in range(n): + if runs[k] > runs[maxi]: + maxi = k + t_runs += runs[k] +print(t_runs) +print(maxi) From b66e998199b061e94fd224a952a846381342eeb9 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:47:31 +0530 Subject: [PATCH 03/45] Delete December 01/DOA_01.py --- December 01/DOA_01.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 December 01/DOA_01.py diff --git a/December 01/DOA_01.py b/December 01/DOA_01.py deleted file mode 100644 index 1ee1374..0000000 --- a/December 01/DOA_01.py +++ /dev/null @@ -1,9 +0,0 @@ -n = int(input()) -runs = [int(i) for i in input().split()] -maxi, t_runs = 0, 0 -for k in range(n): - if runs[k] > runs[maxi]: - maxi = k - t_runs += runs[k] -print(t_runs) -print(maxi) From a2783a6b560ddd267533b9d4ead86aca28f2727b Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:48:46 +0530 Subject: [PATCH 04/45] Create python3_Divyadharshan_Cricmetric.py --- December 01/python3_Divyadharshan_Cricmetric.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 01/python3_Divyadharshan_Cricmetric.py diff --git a/December 01/python3_Divyadharshan_Cricmetric.py b/December 01/python3_Divyadharshan_Cricmetric.py new file mode 100644 index 0000000..1ee1374 --- /dev/null +++ b/December 01/python3_Divyadharshan_Cricmetric.py @@ -0,0 +1,9 @@ +n = int(input()) +runs = [int(i) for i in input().split()] +maxi, t_runs = 0, 0 +for k in range(n): + if runs[k] > runs[maxi]: + maxi = k + t_runs += runs[k] +print(t_runs) +print(maxi) From ac6d12a686a6bf8dc5492a0c6a6a37e7399d5671 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:21:28 +0530 Subject: [PATCH 05/45] Create python3_Divyadharshan_ShoppersChoice.py --- December 02 /python3_Divyadharshan_ShoppersChoice.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 December 02 /python3_Divyadharshan_ShoppersChoice.py diff --git a/December 02 /python3_Divyadharshan_ShoppersChoice.py b/December 02 /python3_Divyadharshan_ShoppersChoice.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/December 02 /python3_Divyadharshan_ShoppersChoice.py @@ -0,0 +1 @@ + From 1f41b6a107893e584b26e2d0d3a4a704d440f6d4 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:23:22 +0530 Subject: [PATCH 06/45] Update python3_Divyadharshan_ShoppersChoice.py --- December 02 /python3_Divyadharshan_ShoppersChoice.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/December 02 /python3_Divyadharshan_ShoppersChoice.py b/December 02 /python3_Divyadharshan_ShoppersChoice.py index 8b13789..5dc85a5 100644 --- a/December 02 /python3_Divyadharshan_ShoppersChoice.py +++ b/December 02 /python3_Divyadharshan_ShoppersChoice.py @@ -1 +1,8 @@ - +p = [int(i) for i in input().split()] +dd = {} +for i in p: + if i not in dd: + dd[i] = 1 + else: + dd[i] += 1 +print(list(dd.values())) From 9b5cf9472122f74ef7b0ddd9b85cd0cb2b360758 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:27:15 +0530 Subject: [PATCH 07/45] Create python3_Divyadharshan_Sunburnt.py --- December 03/python3_Divyadharshan_Sunburnt.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December 03/python3_Divyadharshan_Sunburnt.py diff --git a/December 03/python3_Divyadharshan_Sunburnt.py b/December 03/python3_Divyadharshan_Sunburnt.py new file mode 100644 index 0000000..b7b2710 --- /dev/null +++ b/December 03/python3_Divyadharshan_Sunburnt.py @@ -0,0 +1,8 @@ +n=int(input()) +h=[int(i) for i in input().split()] +s=1 +for i in range(1,n): + v=h[:i] + if h[i]>=max(v): + s+=1 +print(s) From adf027705b47645fb47b94ffe938d1127221d0d6 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:37:28 +0530 Subject: [PATCH 08/45] Update python3_Divyadharshan_Sunburnt.py --- December 03/python3_Divyadharshan_Sunburnt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/December 03/python3_Divyadharshan_Sunburnt.py b/December 03/python3_Divyadharshan_Sunburnt.py index b7b2710..df8fad9 100644 --- a/December 03/python3_Divyadharshan_Sunburnt.py +++ b/December 03/python3_Divyadharshan_Sunburnt.py @@ -1,8 +1,9 @@ n=int(input()) h=[int(i) for i in input().split()] s=1 +m=h[0] for i in range(1,n): - v=h[:i] - if h[i]>=max(v): + if h[i]>=m: s+=1 + m=h[i] print(s) From cd6a535576578443426a50f0b227c6062a51fcaf Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:52:49 +0530 Subject: [PATCH 09/45] Create python3_Divyadharshan_MirrorMagic.py --- December 04/python3_Divyadharshan_MirrorMagic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December 04/python3_Divyadharshan_MirrorMagic.py diff --git a/December 04/python3_Divyadharshan_MirrorMagic.py b/December 04/python3_Divyadharshan_MirrorMagic.py new file mode 100644 index 0000000..ee265e4 --- /dev/null +++ b/December 04/python3_Divyadharshan_MirrorMagic.py @@ -0,0 +1,12 @@ +s=input().strip() +p=[] +for i in range(len(s)): + for j in range(i,len(s)): + if s[i:j+1]==s[i:j+1][::-1]: + if len(s[i:j+1])!=1: + p.append(s[i:j+1]) +p.sort(key=len) +if p: + print(p[0]) +else: + print("Error") From b7b0a1a161cb8ebb4c0731565c60b160e494ae28 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:25:55 +0530 Subject: [PATCH 10/45] Create python3_Divyadharshan_PeakyBlinders.py --- December 05/python3_Divyadharshan_PeakyBlinders.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 December 05/python3_Divyadharshan_PeakyBlinders.py diff --git a/December 05/python3_Divyadharshan_PeakyBlinders.py b/December 05/python3_Divyadharshan_PeakyBlinders.py new file mode 100644 index 0000000..ddde035 --- /dev/null +++ b/December 05/python3_Divyadharshan_PeakyBlinders.py @@ -0,0 +1,7 @@ +t = [int(i) for i in input().split()] +ave = sum(t)/len(t) +s = 0 +for i in t: + if i>=ave: + s+=i +print(s) From 53778b1b2a2ca74313aa746e1c201edffa3a8b9b Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:44:51 +0530 Subject: [PATCH 11/45] Create python3_Divyadharshan_TheLostAlgorithmScrolls.py --- ...3_Divyadharshan_TheLostAlgorithmScrolls.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 December 06/python3_Divyadharshan_TheLostAlgorithmScrolls.py diff --git a/December 06/python3_Divyadharshan_TheLostAlgorithmScrolls.py b/December 06/python3_Divyadharshan_TheLostAlgorithmScrolls.py new file mode 100644 index 0000000..e9a4685 --- /dev/null +++ b/December 06/python3_Divyadharshan_TheLostAlgorithmScrolls.py @@ -0,0 +1,21 @@ +w=[i for i in input().split()] +def comp(w1,w2): + c=0 + for i in range(len(w1)): + if w1[i]!=w2[i]: + c-=-1 + if c>1: + return False + return c==1 +d={} +f=0 +for i in range(1,len(w)): + if len(w[i])==len(w[i-1]): + if comp(w[i],w[i-1]): + d[w[i-1]]=1 + d[w[i]]=1 + f=1 +if f: + print(list(d.keys())) +else: + print("No valid chain.") From 73fa08088c6c56d0c57a3cc87e7599b51cd76663 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:22:07 +0530 Subject: [PATCH 12/45] Create python3_Divyadharshan_BabyBlocks.py --- December 07/python3_Divyadharshan_BabyBlocks.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December 07/python3_Divyadharshan_BabyBlocks.py diff --git a/December 07/python3_Divyadharshan_BabyBlocks.py b/December 07/python3_Divyadharshan_BabyBlocks.py new file mode 100644 index 0000000..2074fcb --- /dev/null +++ b/December 07/python3_Divyadharshan_BabyBlocks.py @@ -0,0 +1,8 @@ +w,h,r=[int(i) for i in input().split()] +def rectangleInCircle(w,h,r): + d=(w**2+h**2)**0.5 + if d<=r*2: + print("true") + else: + print("false") +rectangleInCircle(w,h,r) From 10c7ad1e198cb437cabeceada7ef3eececa42566 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:06:16 +0530 Subject: [PATCH 13/45] Create python3_Divyadharshan_TheEnchantedForest.py --- ...ython3_Divyadharshan_TheEnchantedForest.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 December 08/python3_Divyadharshan_TheEnchantedForest.py diff --git a/December 08/python3_Divyadharshan_TheEnchantedForest.py b/December 08/python3_Divyadharshan_TheEnchantedForest.py new file mode 100644 index 0000000..3ecbcca --- /dev/null +++ b/December 08/python3_Divyadharshan_TheEnchantedForest.py @@ -0,0 +1,21 @@ +#Using **Siamese method** also known as the De la Loubère method, a method for constructing magic squares of odd order where row, columns and diagonals have same sum. + +def find_path(n): + pa = [[0]*n for p in range(n)] + i,j=0,n//2 + for k in range(1,n*n+1): + pa[i][j]=k + i-=1 + j-=-1 + if k%n==0: + i-=-2 + j-=1 + else: + if j==n: + j-=n + elif i<0: + i-=-n + for k in pa: + print(*k) + +find_path(int(input())) From 1b607777722f2187709b22aab8568c77ec7340d2 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:21:32 +0530 Subject: [PATCH 14/45] Create python3_Divyadharshan_CamelsOnAString.py --- python3_Divyadharshan.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 python3_Divyadharshan.py diff --git a/python3_Divyadharshan.py b/python3_Divyadharshan.py new file mode 100644 index 0000000..9a3db1d --- /dev/null +++ b/python3_Divyadharshan.py @@ -0,0 +1,6 @@ +s=input().strip() +w=1 +for i in s: + if 65<=ord(i)<=90: + w+=1 +print(w) From 1a7fedda2d0a14fc5e840b3b014239ad56ac9a32 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:21:59 +0530 Subject: [PATCH 15/45] Delete python3_Divyadharshan.py --- python3_Divyadharshan.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 python3_Divyadharshan.py diff --git a/python3_Divyadharshan.py b/python3_Divyadharshan.py deleted file mode 100644 index 9a3db1d..0000000 --- a/python3_Divyadharshan.py +++ /dev/null @@ -1,6 +0,0 @@ -s=input().strip() -w=1 -for i in s: - if 65<=ord(i)<=90: - w+=1 -print(w) From 21e881e0d3e96ebe1d45f0e7fdd949784adeb254 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:23:29 +0530 Subject: [PATCH 16/45] Create python3_Divyadharshan_CamelsOnAString.py --- December 09/python3_Divyadharshan_CamelsOnAString.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 December 09/python3_Divyadharshan_CamelsOnAString.py diff --git a/December 09/python3_Divyadharshan_CamelsOnAString.py b/December 09/python3_Divyadharshan_CamelsOnAString.py new file mode 100644 index 0000000..9a3db1d --- /dev/null +++ b/December 09/python3_Divyadharshan_CamelsOnAString.py @@ -0,0 +1,6 @@ +s=input().strip() +w=1 +for i in s: + if 65<=ord(i)<=90: + w+=1 +print(w) From 3891e4c34eacc537c5b3e7580982a83b25afc176 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Sun, 10 Dec 2023 21:56:26 +0530 Subject: [PATCH 17/45] Create python3_Divyadharshan_ForgotPassword.py --- December 10/python3_Divyadharshan_ForgotPassword.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 December 10/python3_Divyadharshan_ForgotPassword.py diff --git a/December 10/python3_Divyadharshan_ForgotPassword.py b/December 10/python3_Divyadharshan_ForgotPassword.py new file mode 100644 index 0000000..f264ed4 --- /dev/null +++ b/December 10/python3_Divyadharshan_ForgotPassword.py @@ -0,0 +1,7 @@ +import re +t=["Shivnash Kumar","Ragul Gupta"] +query=input().split() +st=query[1] +l=[int(k) for k in re.findall('[0-9]+',st)] +for i in range(len(t)): + print(t[i][l[0]-1:l[0]+l[1]-1]) From 75d070dcaae57b10391b4bd998f0c630e737efb2 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:40:16 +0530 Subject: [PATCH 18/45] Create python3_Divyadharshan_CoderOfConversions.py --- December 11/python3_Divyadharshan_CoderOfConversions.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 December 11/python3_Divyadharshan_CoderOfConversions.py diff --git a/December 11/python3_Divyadharshan_CoderOfConversions.py b/December 11/python3_Divyadharshan_CoderOfConversions.py new file mode 100644 index 0000000..433d4a6 --- /dev/null +++ b/December 11/python3_Divyadharshan_CoderOfConversions.py @@ -0,0 +1,7 @@ +k,p=[int(i) for i in input().split()] +k=k+p +p="" +while k: + p=str(k%2)+p + k//=2 +print(p) From 221f4bf7e6f26d5fd734db875562db77ea20c8da Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:08:35 +0530 Subject: [PATCH 19/45] Create python3_Divyadharshan_TheHeist.py --- December 12/python3_Divyadharshan_TheHeist.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 12/python3_Divyadharshan_TheHeist.py diff --git a/December 12/python3_Divyadharshan_TheHeist.py b/December 12/python3_Divyadharshan_TheHeist.py new file mode 100644 index 0000000..a2d2fa6 --- /dev/null +++ b/December 12/python3_Divyadharshan_TheHeist.py @@ -0,0 +1,25 @@ +box1=[i for i in input().split()] +box2=[i for i in input().split()] +box3=[i for i in input().split()] +def search(k): + l=0 + h=len(k)-1 + while l<=h: + m=(l+h)//2 + if k[m]=="Gold": + return 1 + else: + if k[m]<"Gold": + l=m+1 + else: + h=m-1 + return 0 +box1.sort() +box2.sort() +box3.sort() +if search(box1): + print("Box1 Contains the Gold") +elif search(box2): + print("Box2 Contains the Gold") +elif search(box3): + print("Box3 Contains the Gold") From 8c1f7448f2fa3a2150f40b07fa0bf40e409c8799 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Wed, 13 Dec 2023 19:31:19 +0530 Subject: [PATCH 20/45] Create python3_Divyadharshan_CallCipher.py --- December 13/python3_Divyadharshan_CallCipher.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 December 13/python3_Divyadharshan_CallCipher.py diff --git a/December 13/python3_Divyadharshan_CallCipher.py b/December 13/python3_Divyadharshan_CallCipher.py new file mode 100644 index 0000000..5b7ae36 --- /dev/null +++ b/December 13/python3_Divyadharshan_CallCipher.py @@ -0,0 +1,14 @@ +d={"ABC":2,"DEF":3,"GHI":4,"JKL":5,"MNO":6,"PQRS":7,"TUV":8,"WXYZ":9} +s=input() +def textToNum(v): + s="" + for i in v: + if 65<=ord(i)<=90: + for j in d: + if i in j: + s+=str(d[j]) + break + else: + s+=i + print(s) +textToNum(s) From ff078d6d73baf5bb1bc84ac57a57a50cfa28450a Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:24:19 +0530 Subject: [PATCH 21/45] Create python3_Divyadharshan_SubsequenceSorcery.py --- December 15/python3_Divyadharshan_SubsequenceSorcery.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 15/python3_Divyadharshan_SubsequenceSorcery.py diff --git a/December 15/python3_Divyadharshan_SubsequenceSorcery.py b/December 15/python3_Divyadharshan_SubsequenceSorcery.py new file mode 100644 index 0000000..ac86695 --- /dev/null +++ b/December 15/python3_Divyadharshan_SubsequenceSorcery.py @@ -0,0 +1,9 @@ +from itertools import combinations +l=[""] +k=input().strip() +for p in range(len(k)): + for i in combinations(k,p+1): + s="".join(i) + if s not in l: + l.append(s) +print(len(l)) From e35ae698aae3a5c1ae6e85293199aa3a1c0a8d0c Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:22:15 +0530 Subject: [PATCH 22/45] Create python3_Divyadharshan_CallOfJustice.cpp --- .../python3_Divyadharshan_CallOfJustice.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 December 14/python3_Divyadharshan_CallOfJustice.cpp diff --git a/December 14/python3_Divyadharshan_CallOfJustice.cpp b/December 14/python3_Divyadharshan_CallOfJustice.cpp new file mode 100644 index 0000000..b4a93c1 --- /dev/null +++ b/December 14/python3_Divyadharshan_CallOfJustice.cpp @@ -0,0 +1,74 @@ +#include +#include +using namespace std; + +class TreeNode { +public: + int value; + TreeNode* left; + TreeNode* right; + + TreeNode(int val) : value(val), left(nullptr), right(nullptr) {} +}; + +void findKDistanceNodes(TreeNode* root, int target, int k, vector& result) { + if (!root) + return; + + if (k == 0) { + result.push_back(root->value); + return; + } + + findKDistanceNodes(root->left, target, k - 1, result); + findKDistanceNodes(root->right, target, k - 1, result); +} + +int findTarget(TreeNode* root, int target, int k, vector& result) { + if (!root) + return -1; + + if (root->value == target) { + findKDistanceNodes(root, target, k, result); + return 0; + } + + int leftDistance = findTarget(root->left, target, k, result); + if (leftDistance >= 0) { + if (leftDistance + 1 == k) + result.push_back(root->value); + + findKDistanceNodes(root->right, target, k - leftDistance - 2, result); + return leftDistance + 1; + } + + int rightDistance = findTarget(root->right, target, k, result); + if (rightDistance >= 0) { + if (rightDistance + 1 == k) + result.push_back(root->value); + + findKDistanceNodes(root->left, target, k - rightDistance - 2, result); + return rightDistance + 1; + } + return -1; +} + +int main() { + TreeNode* root = new TreeNode(17); + root->left = new TreeNode(8); + root->right = new TreeNode(27); + root->left->left = new TreeNode(4); + root->left->right = new TreeNode(14); + root->left->right->left = new TreeNode(10); + root->left->right->right = new TreeNode(16); + int targetNode = 8; + int kDistance = 2; + vector output; + findTarget(root, targetNode, kDistance, output); + sort(output.begin(),output.end()); + for (int node : output) { + cout << node << " "; + } + cout << endl; + return 0; +} From f86d13a7d1020f59b4dba4c90e2a7315c100da2f Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:36:38 +0530 Subject: [PATCH 23/45] Rename python3_Divyadharshan_CallOfJustice.cpp to C++_Divyadharshan_CallOfJustice.cpp --- ...shan_CallOfJustice.cpp => c++_Divyadharshan_CallOfJustice.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 14/{python3_Divyadharshan_CallOfJustice.cpp => c++_Divyadharshan_CallOfJustice.cpp} (100%) diff --git a/December 14/python3_Divyadharshan_CallOfJustice.cpp b/December 14/c++_Divyadharshan_CallOfJustice.cpp similarity index 100% rename from December 14/python3_Divyadharshan_CallOfJustice.cpp rename to December 14/c++_Divyadharshan_CallOfJustice.cpp From bab3a3c0fd88bed1cc4d16f0dbbf79bda1b55f0d Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:37:12 +0530 Subject: [PATCH 24/45] Update c++_Divyadharshan_CallOfJustice.cpp --- December 14/c++_Divyadharshan_CallOfJustice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/December 14/c++_Divyadharshan_CallOfJustice.cpp b/December 14/c++_Divyadharshan_CallOfJustice.cpp index b4a93c1..d0f5661 100644 --- a/December 14/c++_Divyadharshan_CallOfJustice.cpp +++ b/December 14/c++_Divyadharshan_CallOfJustice.cpp @@ -10,7 +10,6 @@ class TreeNode { TreeNode(int val) : value(val), left(nullptr), right(nullptr) {} }; - void findKDistanceNodes(TreeNode* root, int target, int k, vector& result) { if (!root) return; From d99b67c85d99ab67d46407151f41b496543dc203 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:38:32 +0530 Subject: [PATCH 25/45] Create C++_Divyadharshan_BookshelfDilemma.cpp --- .../C++_Divyadharshan_BookshelfDilemma.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 December 17/C++_Divyadharshan_BookshelfDilemma.cpp diff --git a/December 17/C++_Divyadharshan_BookshelfDilemma.cpp b/December 17/C++_Divyadharshan_BookshelfDilemma.cpp new file mode 100644 index 0000000..320771a --- /dev/null +++ b/December 17/C++_Divyadharshan_BookshelfDilemma.cpp @@ -0,0 +1,74 @@ +#include +using namespace std; + +struct Node { + int data; + struct Node* next; +}; + +void removeLoop(struct Node* loop_node, struct Node* head) +{ + struct Node* ptr1 = loop_node; + struct Node* ptr2 = loop_node; + unsigned int k = 1, i; + while (ptr1->next != ptr2) { + ptr1 = ptr1->next; + k++; + } + ptr1 = head; + ptr2 = head; + for (i = 0; i < k; i++) + ptr2 = ptr2->next; + + while (ptr2 != ptr1) { + ptr1 = ptr1->next; + ptr2 = ptr2->next; + } + while (ptr2->next != ptr1) + ptr2 = ptr2->next; + + ptr2->next = NULL; +} + +int detectAndRemoveLoop(struct Node* list) +{ + struct Node *slow_p = list, *fast_p = list; + while (slow_p && fast_p && fast_p->next) { + slow_p = slow_p->next; + fast_p = fast_p->next->next; + if (slow_p == fast_p) { + removeLoop(slow_p, list); + return 1; + } + } + return 0; +} + +void printList(struct Node* node) +{ + while (node!=NULL) { + cout << node->data << " "; + node = node->next; + } +} + +struct Node* newNode(int key) +{ + struct Node* temp = new Node(); + temp->data = key; + temp->next = NULL; + return temp; +} + +int main() +{ + struct Node* head = newNode(1); + head->next = newNode(2); + head->next->next = newNode(3); + head->next->next->next = newNode(4); + head->next->next->next->next = newNode(5); + head->next->next->next->next->next = head->next->next->next; + detectAndRemoveLoop(head); + printList(head); + return 0; +} From 794d081dabf4cac4c03ebc595c9a169f86636d5d Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:40:21 +0530 Subject: [PATCH 26/45] Delete December 02 directory --- December 02/.gitignore | 231 ----------------------------------------- 1 file changed, 231 deletions(-) delete mode 100644 December 02/.gitignore diff --git a/December 02/.gitignore b/December 02/.gitignore deleted file mode 100644 index 8e0ca25..0000000 --- a/December 02/.gitignore +++ /dev/null @@ -1,231 +0,0 @@ -# gitignore file for "A December of Algorithms 2023" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# node.js -/node_modules -package-lock.json - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -Pipfile.lock -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# Files and directories created by pub -.dart_tool/ -.packages -build/ -# If you're building an application, you may want to check-in your pubspec.lock -pubspec.lock - -# Directory created by dartdoc -# If you don't generate documentation locally you can remove this line. -doc/api/ - -# Avoid committing generated Javascript files: -*.dart.js -*.info.json # Produced by the --dump-info flag. -*.js # When generated by dart2js. Don't specify *.js if your - # project includes source files written in JavaScript. -*.js_ -*.js.deps -*.js.map - -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf From 9fab3d3092f3537562a57393e65d666a16684d62 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:41:23 +0530 Subject: [PATCH 27/45] Create python3_Divyadharshan_RiddleMeThis.py --- December 21/python3_Divyadharshan_RiddleMeThis.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 December 21/python3_Divyadharshan_RiddleMeThis.py diff --git a/December 21/python3_Divyadharshan_RiddleMeThis.py b/December 21/python3_Divyadharshan_RiddleMeThis.py new file mode 100644 index 0000000..5be0944 --- /dev/null +++ b/December 21/python3_Divyadharshan_RiddleMeThis.py @@ -0,0 +1,14 @@ +l=input("Enter code : ") +shift=25 +inc=26-shift +um="" +for i in l: + d=ord(i) + if i.islower() and (d+inc)>122: + d=95+inc + elif i.isupper() and (d+inc)>90: + d=64+inc + else: + d=ord(i)+inc + um+=chr(d) +print(f"The Bomb location is : {um} - SHIFT {shift}") From 1132bbb077965b4cf08f243d0a0f9fa54f0a0862 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:11:58 +0530 Subject: [PATCH 28/45] Create python3_Divyadharshan_GoldenRuleViolation.py --- December 24/python3_Divyadharshan_GoldenRuleViolation.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December 24/python3_Divyadharshan_GoldenRuleViolation.py diff --git a/December 24/python3_Divyadharshan_GoldenRuleViolation.py b/December 24/python3_Divyadharshan_GoldenRuleViolation.py new file mode 100644 index 0000000..7ef96fa --- /dev/null +++ b/December 24/python3_Divyadharshan_GoldenRuleViolation.py @@ -0,0 +1,8 @@ +n=int(input()) +l=[int(i) for i in input().split()] +v=0 +for i in range(n-1): + for j in range(i+1,n): + if l[j] Date: Thu, 28 Dec 2023 20:57:45 +0530 Subject: [PATCH 29/45] Create C++_Divyadharshan_ThePhantomCycle.cpp --- .../C++_Divyadharshan_ThePhantomCycle.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 December 26/C++_Divyadharshan_ThePhantomCycle.cpp diff --git a/December 26/C++_Divyadharshan_ThePhantomCycle.cpp b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp new file mode 100644 index 0000000..c73e90a --- /dev/null +++ b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; +struct node +{ + int val; + struct node *next; +}; +struct node *head = NULL; + +bool detectLoop(Node* head) + { + Node* temp = head; + map v; + while(temp!=NULL){ + if(v[temp]!=true){ + v[temp] = true; + temp = temp->next;} + else{ + return true; + } + } + return false; +} +void insert(struct node *head, int val) +{ + struct node *nn = malloc(sizeof(struct node)); + nn->val=val; + nn->next=NULL; + if(head==NULL){ + head=nn; + } + else + { + struct node *t=head; + while(t->next!=NULL) + { + t=t->next; + } + t->next=nn; + } +} + +int main(){ + int n,e; + cin>>n; + for(int i=0; i>e; + insert(head,e); + } + if(detectLoop(head)){ + cout << "Cycle Found"; + } + else{ + cout << "No Cycle Found"; + } +} From b33779d8c916c187d0af01f977263d0c32a830ee Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:03:45 +0530 Subject: [PATCH 30/45] Create python3_Divyadharshan_CartesianWalkValidator.py --- ...ython3_Divyadharshan_CartesianWalkValidator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 December 29/python3_Divyadharshan_CartesianWalkValidator.py diff --git a/December 29/python3_Divyadharshan_CartesianWalkValidator.py b/December 29/python3_Divyadharshan_CartesianWalkValidator.py new file mode 100644 index 0000000..34a56a9 --- /dev/null +++ b/December 29/python3_Divyadharshan_CartesianWalkValidator.py @@ -0,0 +1,15 @@ +walk=[i for i in input().split()] +x,y=0,0 +for i in walk: + if i=="n": + y+=1 + elif i=="s": + y-=1 + elif i=="e": + x+=1 + elif i=="w": + x-=1 +if x==0 and y==0: + print("TRUE") +else: + print("FALSE") From 79ec8234cf2930f99161697d47cdefdd2ebc52b3 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:06:06 +0530 Subject: [PATCH 31/45] Create python3_Divyadharshan_OutbreakDynamics.py --- .../python3_Divyadharshan_OutbreakDynamics.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 16/python3_Divyadharshan_OutbreakDynamics.py diff --git a/December 16/python3_Divyadharshan_OutbreakDynamics.py b/December 16/python3_Divyadharshan_OutbreakDynamics.py new file mode 100644 index 0000000..b829686 --- /dev/null +++ b/December 16/python3_Divyadharshan_OutbreakDynamics.py @@ -0,0 +1,25 @@ +from collections import deque +def mini(grid): + r, c = len(grid), len(grid[0]) + def is_valid(x, y): + return 0 <= x < r and 0 <= y < c + z = deque() + for i in range(r): + for j in range(c): + if grid[i][j] == 1: + z.append((i, j, 0)) + d = [(-1, 0), (1, 0), (0, -1), (0, 1)] + while z: + x, y, t = z.popleft() + for dx, dy in d: + nx, ny = x + dx, y + dy + if is_valid(nx, ny) and grid[nx][ny] == 0: + grid[nx][ny] = 1 + z.append((nx, ny, t + 1)) + for row in grid: + if 0 in row: + return -1 + return t + +g1=[[0, 1, 0, 0],[1, 1, 1, 1],[0, 1, -1, 0],[0, 0, 0, 0]] +print(mini(g1)) From 538dfc214ca01a229c88e11f9cd3b57dd75062ed Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:37:04 +0530 Subject: [PATCH 32/45] Create python3_Divyadharshan_RottenOranges.py --- .../python3_Divyadharshan_RottenOranges.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December 22/python3_Divyadharshan_RottenOranges.py diff --git a/December 22/python3_Divyadharshan_RottenOranges.py b/December 22/python3_Divyadharshan_RottenOranges.py new file mode 100644 index 0000000..a749bfb --- /dev/null +++ b/December 22/python3_Divyadharshan_RottenOranges.py @@ -0,0 +1,29 @@ +from collections import deque +def rottime(grid): + if not grid or not grid[0]: + return 0 + rows, cols = len(grid), len(grid[0]) + f, q = 0, deque() + for i in range(rows): + for j in range(cols): + if grid[i][j] == 1: + f+=1 + elif grid[i][j] == 2: + q.append((i, j, 0)) + if f==0: + return 0 + d=[(-1, 0), (1, 0), (0, -1), (0, 1)] + t=0 + + while q: + i,j,t=q.popleft() + for di,dj in d: + ni,nj=i+di,j+dj + if 0 <= ni < rows and 0 <= nj < cols and grid[ni][nj] == 1: + grid[ni][nj] = 2 + f -= 1 + q.append((ni, nj, t + 1)) + return t if f == 0 else -1 + +grid=[[2, 2, 0, 1]] +print(rottime(grid)) From 482ee430aaa397662424c4d2ee93add208a7a364 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:12:57 +0530 Subject: [PATCH 33/45] Create python3_Divyadharshan_Dominoes.py --- December 23/python3_Divyadharshan_Dominoes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December 23/python3_Divyadharshan_Dominoes.py diff --git a/December 23/python3_Divyadharshan_Dominoes.py b/December 23/python3_Divyadharshan_Dominoes.py new file mode 100644 index 0000000..9ba9b5a --- /dev/null +++ b/December 23/python3_Divyadharshan_Dominoes.py @@ -0,0 +1,18 @@ +def mintime(n, dominoes): + upper_sum = sum(x[0] for x in dominoes) + lower_sum = sum(x[1] for x in dominoes) + + if upper_sum % 2 == 0 and lower_sum % 2 == 0: + return 0 + elif (upper_sum % 2 == 1 and lower_sum % 2 == 0) or (upper_sum % 2 == 0 and lower_sum % 2 == 1): + return -1 + else: + for i in range(n): + if dominoes[i][0] % 2 == 0 and dominoes[i][1] % 2 == 1: + return 1 + elif dominoes[i][0] % 2 == 1 and dominoes[i][1] % 2 == 0: + return 1 + return -1 +n=2 +dominoes=[[4, 2],[6, 4]] +print(mintime(n,dominoes)) From bed5fb53e74476ba8a5fc243c57e107cb57a9e35 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:18:44 +0530 Subject: [PATCH 34/45] Create python3_Divyadharshan_HarmonyHurdle.py --- .../python3_Divyadharshan_HarmonyHurdle.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December 25/python3_Divyadharshan_HarmonyHurdle.py diff --git a/December 25/python3_Divyadharshan_HarmonyHurdle.py b/December 25/python3_Divyadharshan_HarmonyHurdle.py new file mode 100644 index 0000000..c8ea8bd --- /dev/null +++ b/December 25/python3_Divyadharshan_HarmonyHurdle.py @@ -0,0 +1,37 @@ +from collections import defaultdict, deque + +def min_time(tasks, deps): + g, in_deg, d = defaultdict(list), [0] * len(tasks), [0] * len(tasks) + + for i, dep in enumerate(deps): + for d in dep: + g[d].append(i) + in_deg[i] += 1 + + o, q = [], deque([i for i in range(len(tasks)) if in_deg[i] == 0]) + + while q: + t = q.popleft() + o.append(t) + + for n in g[t]: + in_deg[n] -= 1 + d[n] = max(d[n], d[t] + 1) + + if in_deg[n] == 0: + q.append(n) + + mt = max(d) + + for t in o: + mt += 1 + d[t] + + return mt + +t1 = [1, 2, 3, 4, 5] +d1 = [[], [1], [2], [3], [4, 1]] +print(min_time(t1, d1)) + +t2 = [1, 2, 3, 4, 5] +d2 = [[], [1], [2], [3], [4]] +print(min_time(t2, d2)) From 466828b924156b442481335b017d90402d1920d8 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:22:02 +0530 Subject: [PATCH 35/45] Update C++_Divyadharshan_ThePhantomCycle.cpp --- December 26/C++_Divyadharshan_ThePhantomCycle.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/December 26/C++_Divyadharshan_ThePhantomCycle.cpp b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp index c73e90a..b115bac 100644 --- a/December 26/C++_Divyadharshan_ThePhantomCycle.cpp +++ b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; struct node { From eb65acaf6602945020e27f548081aa0edc45dc07 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:34:37 +0530 Subject: [PATCH 36/45] Create python3_Divyadharshan_CircleOfEndurance.py --- .../python3_Divyadharshan_CircleOfEndurance.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 December 27/python3_Divyadharshan_CircleOfEndurance.py diff --git a/December 27/python3_Divyadharshan_CircleOfEndurance.py b/December 27/python3_Divyadharshan_CircleOfEndurance.py new file mode 100644 index 0000000..8b8b6a9 --- /dev/null +++ b/December 27/python3_Divyadharshan_CircleOfEndurance.py @@ -0,0 +1,11 @@ +def starting_point(N, petrol, distance): + c=0 + for i in range(N): + if distance[i]>petrol[i]: + c-=-1 + return c + +N=4 +petrol=[4, 6, 7, 4] +distance=[6, 5, 3, 5] +print(starting_point(N,petrol,distance)) From bbd4e501ab031f13ad776842c5cbc6f9b8b44e91 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:52:31 +0530 Subject: [PATCH 37/45] Create python3_Divyadharshan_TheSellingGame.py --- .../python3_Divyadharshan_TheSellingGame.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 28/python3_Divyadharshan_TheSellingGame.py diff --git a/December 28/python3_Divyadharshan_TheSellingGame.py b/December 28/python3_Divyadharshan_TheSellingGame.py new file mode 100644 index 0000000..8ae1906 --- /dev/null +++ b/December 28/python3_Divyadharshan_TheSellingGame.py @@ -0,0 +1,32 @@ +def max_gadgets_sold(x, z, items, clients): + items.sort(key=lambda item: item['m'], reverse=True) + clients.sort(key=lambda client: client['k']) + + gadgets_sold = 0 + sold_items = set() + + for client in clients: + for i, item in enumerate(items): + if i not in sold_items and item['m'] > client['k'] and item['n'] <= client['r']: + gadgets_sold += 1 + sold_items.add(i) + break + + return gadgets_sold + +x = 3 +z = 3 +items = [ + {'k': 10, 'r': 100, 'm': 5, 'n': 110}, # Item 0 + {'k': 9, 'r': 200, 'm': 2, 'n': 200}, # Item 1 + {'k': 20, 'r': 300, 'm': 30, 'n': 300} # Item 2 +] + +clients = [ + {'k': 5, 'r': 110}, # Client 0 + {'k': 9, 'r': 500}, # Client 1 + {'k': 20, 'r': 400}, # Client 2 +] + +result = max_gadgets_sold(x, z, items, clients) +print(result) From 023726362ed011091f94c4e633e7d8b03ca0e646 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:30:35 +0530 Subject: [PATCH 38/45] Update C++_Divyadharshan_ThePhantomCycle.cpp --- December 26/C++_Divyadharshan_ThePhantomCycle.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/December 26/C++_Divyadharshan_ThePhantomCycle.cpp b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp index b115bac..75ac926 100644 --- a/December 26/C++_Divyadharshan_ThePhantomCycle.cpp +++ b/December 26/C++_Divyadharshan_ThePhantomCycle.cpp @@ -1,4 +1,4 @@ -#include +#include #include using namespace std; struct node @@ -8,10 +8,10 @@ struct node }; struct node *head = NULL; -bool detectLoop(Node* head) +bool detectLoop(struct node* head) { - Node* temp = head; - map v; + struct node* temp = head; + map v; while(temp!=NULL){ if(v[temp]!=true){ v[temp] = true; @@ -22,9 +22,9 @@ bool detectLoop(Node* head) } return false; } -void insert(struct node *head, int val) +void insert(int val) { - struct node *nn = malloc(sizeof(struct node)); + struct node *nn = (struct node*)malloc(sizeof(struct node)); nn->val=val; nn->next=NULL; if(head==NULL){ @@ -46,8 +46,9 @@ int main(){ cin>>n; for(int i=0; i>e; - insert(head,e); + insert(e); } + head->next->next->next->next=head; if(detectLoop(head)){ cout << "Cycle Found"; } From 54f06ea52b5171a202595a6185d7b1cf42ce6bdf Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:57:15 +0530 Subject: [PATCH 39/45] Create C++_Divyadharshan_SymbolicSum.cpp --- December 19/C++_Divyadharshan_SymbolicSum.cpp | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December 19/C++_Divyadharshan_SymbolicSum.cpp diff --git a/December 19/C++_Divyadharshan_SymbolicSum.cpp b/December 19/C++_Divyadharshan_SymbolicSum.cpp new file mode 100644 index 0000000..8abe56a --- /dev/null +++ b/December 19/C++_Divyadharshan_SymbolicSum.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +using namespace std; + +int symSum(const string& kp) { + stack> st; + + int multiplier = 1; + long long sum = 0; + + for (char ch:kp) { + if (isdigit(ch)) { + sum += ch - '0'; + } else if (ch=='X') { + st.push({sum, multiplier}); + sum = 0; + multiplier = 1; + } else if (ch==' ') { + continue; + } else { + multiplier=ch-'0'; + } + } + + long long sSum = 0; + + while (!st.empty()) { + auto top = st.top(); + st.pop(); + sSum+= top.first * top.second; + } + return sSum; +} + +int main() { + string s = "X1 1 X2 4 X3 4 5"; + cout << "Symbolic Sum: " << symSum(s) << endl; + return 0; +} From b187ce0e3502ff45bf4d835373869b05f3e5fa70 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:58:01 +0530 Subject: [PATCH 40/45] Rename c++_Divyadharshan_CallOfJustice.cpp to C++_Divyadharshan_CallOfJustice.cpp --- ...shan_CallOfJustice.cpp => C++_Divyadharshan_CallOfJustice.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 14/{c++_Divyadharshan_CallOfJustice.cpp => C++_Divyadharshan_CallOfJustice.cpp} (100%) diff --git a/December 14/c++_Divyadharshan_CallOfJustice.cpp b/December 14/C++_Divyadharshan_CallOfJustice.cpp similarity index 100% rename from December 14/c++_Divyadharshan_CallOfJustice.cpp rename to December 14/C++_Divyadharshan_CallOfJustice.cpp From 0a5577d16645b72844484478ad3d201f5427d034 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:59:13 +0530 Subject: [PATCH 41/45] Update C++_Divyadharshan_CallOfJustice.cpp --- December 14/C++_Divyadharshan_CallOfJustice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/December 14/C++_Divyadharshan_CallOfJustice.cpp b/December 14/C++_Divyadharshan_CallOfJustice.cpp index d0f5661..b4a93c1 100644 --- a/December 14/C++_Divyadharshan_CallOfJustice.cpp +++ b/December 14/C++_Divyadharshan_CallOfJustice.cpp @@ -10,6 +10,7 @@ class TreeNode { TreeNode(int val) : value(val), left(nullptr), right(nullptr) {} }; + void findKDistanceNodes(TreeNode* root, int target, int k, vector& result) { if (!root) return; From 90d4574ab727682ea067880695f50c71e1e32fe6 Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:12:08 +0530 Subject: [PATCH 42/45] Create python3_Divyadharshan_TreasureHuntInTheIsles.py --- ...n3_Divyadharshan_TreasureHuntInTheIsles.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December 20/python3_Divyadharshan_TreasureHuntInTheIsles.py diff --git a/December 20/python3_Divyadharshan_TreasureHuntInTheIsles.py b/December 20/python3_Divyadharshan_TreasureHuntInTheIsles.py new file mode 100644 index 0000000..2ad4999 --- /dev/null +++ b/December 20/python3_Divyadharshan_TreasureHuntInTheIsles.py @@ -0,0 +1,22 @@ +import heapq +def hunt(g, s, e): + q = [(0, s, [s])] + while q: + tw, cc, pf = heapq.heappop(q) + if cc == e: + return pf + for n, w in g.get(cc, {}).items(): + tnw = tw + w + heapq.heappush(q, (tnw, n, pf + [n])) + return [] + +graph={ + 'Cave_A': {'Cave_B': 4, 'Cave_C': 6}, + 'Cave_B': {'Cave_C': 2, 'Cave_D': 5, 'Cave_E': 8}, + 'Cave_C': {'Cave_A': 6, 'Cave_D': 7}, + 'Cave_D': {'Cave_B': 5, 'Cave_E': 3}, + 'Cave_E': {} +} +start_cave2 = 'Cave_B' +end_cave2 = 'Cave_E' +print(hunt(graph, start_cave2, end_cave2)) From d54329e8b96343bf183023073d48486da9dc892f Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:35:15 +0530 Subject: [PATCH 43/45] Create python3_Divyadharshan_It'sChristmasSeason.py --- ...thon3_Divyadharshan_It'sChristmasSeason.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 December 18/python3_Divyadharshan_It'sChristmasSeason.py diff --git a/December 18/python3_Divyadharshan_It'sChristmasSeason.py b/December 18/python3_Divyadharshan_It'sChristmasSeason.py new file mode 100644 index 0000000..8cb5909 --- /dev/null +++ b/December 18/python3_Divyadharshan_It'sChristmasSeason.py @@ -0,0 +1,75 @@ +import sys +sys.setrecursionlimit(1000000) +global N, MOD, f, inv +N = 100000 +l=[] +MOD = 10**9+7 +f = [0]*(N + 1) +inv = [0]*(N + 1) +def dfs(node, p, g, a, x): + for c in g[node]: + if c != p: + dfs(c, node, g, a, x) + a[node] += a[c] + if a[node] >= x: + a[node] -= x +def powmod(a, b, mod): + res = 1 + a %= mod + while b: + if b & 1: + res = res * a % mod + a = a * a % mod + b >>= 1 + return res +def cn(u, v, MOD): + if u > v: + return 0 + if u == v: + return 1 + if u == 1 or u + 1 == v: + return v + return f[v] * inv[u] % MOD * inv[v - u] % MOD + +def dfs_count(node, p, g, a): + cnt = 1 if a[node] == 0 else 0 + for c in g[node]: + if c != p: + cnt += dfs_count(c, node, g, a) + return cnt + +def solve(): + global N, MOD, f, inv + n, x = map(int, input().split()) + a = list(map(int, input().split())) + a = [ai % x for ai in a] + g = [[] for _ in range(n)] + for _ in range(n - 1): + u, v = map(int, input().split()) + u -= 1 + v -= 1 + g[u].append(v) + g[v].append(u) + dfs(0, -1, g, a, x) + if a[0] != 0: + print(' '.join(['0'] * n)) + return + result = [1] + cnt = dfs_count(0, -1, g, a) + for i in range(2, n + 1): + result.append(cn(i - 1, cnt - 1, MOD)) + l.append(list(''.join(map(str,result)))) + +f[0] = 1 +for i in range(1, N + 1): + f[i] = f[i - 1] * i % MOD + inv[N] = powmod(f[N], MOD - 2, MOD) +for i in range(N, 0, -1): + inv[i - 1] = inv[i] * i % MOD +t = int(input()) +for _ in range(t): + solve() +for i in l: + for j in i: + print(int(j),end=" ") + print() From 36bf7bb2fa766ac03f860ac400b72987055b141f Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:58:08 +0530 Subject: [PATCH 44/45] Create python3_Divyadharshan_TreeInversions.py --- .../python3_Divyadharshan_TreeInversions.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December 30/python3_Divyadharshan_TreeInversions.py diff --git a/December 30/python3_Divyadharshan_TreeInversions.py b/December 30/python3_Divyadharshan_TreeInversions.py new file mode 100644 index 0000000..b120c6a --- /dev/null +++ b/December 30/python3_Divyadharshan_TreeInversions.py @@ -0,0 +1,43 @@ +def dfs(node, parent, colors, tree, in_count, out_count, depth): + in_count[node] = [0] * depth + out_count[node] = [0] * depth + in_count[node][colors[node] - 1] = 1 + + for child in tree[node]: + if child == parent: + continue + dfs(child, node, colors, tree, in_count, out_count, depth) + for i in range(depth): + in_count[node][i] += in_count[child][i] + out_count[node][i] += out_count[child][i] + out_count[node][colors[node] - 1] += 1 + +def solve_queries(tree, in_count, out_count, depth, queries): + result = [] + for query in queries: + x, y = query + x -= 1 + y -= 1 + total_inversions = 0 + for i in range(depth): + total_inversions += abs(in_count[x][i] - in_count[y][i]) + abs(out_count[x][i] - out_count[y][i]) + result.append(total_inversions // 2) + return result + +T = int(input()) +for _ in range(T): + N, Q = map(int, input().split()) + colors = list(map(int, input().split())) + tree = {i: [] for i in range(N)} + for _ in range(N - 1): + X, Y = map(int, input().split()) + tree[X - 1].append(Y - 1) + tree[Y - 1].append(X - 1) + in_count = {} + out_count = {} + dfs(0, -1, colors, tree, in_count, out_count, max(colors)) + queries = [tuple(map(int, input().split())) for _ in range(Q)] + result = solve_queries(tree, in_count, out_count, max(colors), queries) + + for res in result: + print(res) From 8d29bad545d203da2192c5359e9e3e77f142942b Mon Sep 17 00:00:00 2001 From: Divya Dharshan S <97381430+Divyadharshan@users.noreply.github.com> Date: Fri, 5 Jan 2024 17:01:05 +0530 Subject: [PATCH 45/45] Create python3_Divyadharshan_NQueens.py --- December 31/python3_Divyadharshan_NQueens.py | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 31/python3_Divyadharshan_NQueens.py diff --git a/December 31/python3_Divyadharshan_NQueens.py b/December 31/python3_Divyadharshan_NQueens.py new file mode 100644 index 0000000..88f3061 --- /dev/null +++ b/December 31/python3_Divyadharshan_NQueens.py @@ -0,0 +1,25 @@ +def is_safe(board, row, col, N): + for i in range(row): + if board[i] == col or board[i] - i == col - row or board[i] + i == col + row: + return False + return True + +def solve_nqueens(board, row, N, solutions): + if row == N: + solutions.append(tuple(board[:])) + else: + for col in range(N): + if is_safe(board, row, col, N): + board[row] = col + solve_nqueens(board, row + 1, N, solutions) + +def print_solutions(N): + board = [-1] * N + solutions = [] + solve_nqueens(board, 0, N, solutions) + + for solution in solutions: + print(" ".join(f"({i + 1}, {solution[i] + 1})" for i in range(N))) + +N = int(input()) +print_solutions(N)