From ecead0aade6330a06b40f68145a1ba159515ca65 Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:23:16 +0530 Subject: [PATCH 01/36] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8dfc5ba..2d907c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # IEM-CC-Hacktoberfest + + Can you solve these fundamental programming problems ? You may choose to code in any language of your choice ( C/C++, Java, Python, JS, etc.). If you need any assistance (even if you are stuck in coding out your solutions) contact CC team on Discord. From 511a89e8cd545672b096044f55b7c2cbefb3d410 Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:27:12 +0530 Subject: [PATCH 02/36] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d907c3..65824a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # IEM-CC-Hacktoberfest - +![alt text](https://raw.githubusercontent.com/divyake/Cysec-Hacktoberfest/dcc84465cfcff73981f8fcb5c8fe3b1710c007e1/assets/logo.svg) Can you solve these fundamental programming problems ? From 6e75bc852f3335df0a864fd7bbbf160ca1c83222 Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:27:38 +0530 Subject: [PATCH 03/36] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65824a0..0f22d2e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # IEM-CC-Hacktoberfest ![alt text](https://raw.githubusercontent.com/divyake/Cysec-Hacktoberfest/dcc84465cfcff73981f8fcb5c8fe3b1710c007e1/assets/logo.svg) -Can you solve these fundamental programming problems ? +###Can you solve these fundamental programming problems ? You may choose to code in any language of your choice ( C/C++, Java, Python, JS, etc.). If you need any assistance (even if you are stuck in coding out your solutions) contact CC team on Discord. Prerequisites: Account on Hackerrank , Codechef, Codeforces, GFG. -Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing +####Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) From 33000ff71f3a98e6edeb238f72217fc9788ae42b Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:29:46 +0530 Subject: [PATCH 04/36] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f22d2e..9bcd99f 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # IEM-CC-Hacktoberfest ![alt text](https://raw.githubusercontent.com/divyake/Cysec-Hacktoberfest/dcc84465cfcff73981f8fcb5c8fe3b1710c007e1/assets/logo.svg) -###Can you solve these fundamental programming problems ? +### Can you solve these fundamental programming problems ? You may choose to code in any language of your choice ( C/C++, Java, Python, JS, etc.). If you need any assistance (even if you are stuck in coding out your solutions) contact CC team on Discord. Prerequisites: Account on Hackerrank , Codechef, Codeforces, GFG. -####Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing +#### Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing -Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) +> Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) Left Rotation: https://www.hackerrank.com/challenges/array-left-rotation/problem ( Head to folder for more details) From 5d06d8e3902dcbc63d31c83461ee6915ae236840 Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:34:17 +0530 Subject: [PATCH 05/36] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9bcd99f..f28ea96 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,20 @@ Prerequisites: Account on Hackerrank , Codechef, Codeforces, GFG. #### Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing -> Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) +i. Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) -Left Rotation: https://www.hackerrank.com/challenges/array-left-rotation/problem ( Head to folder for more details) +ii. Left Rotation: https://www.hackerrank.com/challenges/array-left-rotation/problem ( Head to folder for more details) -Omkar and Password: https://codeforces.com/problemset/problem/1392/A ( Head to folder for more details) +iii. Omkar and Password: https://codeforces.com/problemset/problem/1392/A ( Head to folder for more details) -Stone: https://codeforces.com/problemset/problem/1236/A ( Head to folder for more details) +iv. Stone: https://codeforces.com/problemset/problem/1236/A ( Head to folder for more details) -Bad Triangle: https://codeforces.com/problemset/problem/1398/A ( Head to folder for more details) +v. Bad Triangle: https://codeforces.com/problemset/problem/1398/A ( Head to folder for more details) -Chef and Work: https://www.codechef.com/COOK121B/problems/CHEFNWRK ( Head to folder for more details) +vi. Chef and Work: https://www.codechef.com/COOK121B/problems/CHEFNWRK ( Head to folder for more details) -Chef and Recipe: https://www.codechef.com/COOK118B/problems/CHEFRECP ( Head to folder for more details) +vii. Chef and Recipe: https://www.codechef.com/COOK118B/problems/CHEFRECP ( Head to folder for more details) -Three Friends: https://codeforces.com/problemset/problem/1272/A ( Head to folder for more details) +viii. Three Friends: https://codeforces.com/problemset/problem/1272/A ( Head to folder for more details) -Happy Coding! +`Happy Coding!` :thumbsup: From 8c7c271ccc288bd89f63a6710ec8669183db694d Mon Sep 17 00:00:00 2001 From: Indra Adhikary <43936212+IndraAdhikary@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:40:05 +0530 Subject: [PATCH 06/36] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f28ea96..37cf6b3 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,20 @@ Prerequisites: Account on Hackerrank , Codechef, Codeforces, GFG. #### Fill this sheet to validate your solutions as a member of DSC-IEM: https://docs.google.com/spreadsheets/d/1N5Q4S1zyA8OrRy6pivJB0C-NkR6p2KuZ1mbLj9etKsg/edit?usp=sharing -i. Dynamic Array: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to folder for more details) +i. **Dynamic Array**: https://www.hackerrank.com/challenges/dynamic-array/problem ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Dynamic%20Array) for more details) -ii. Left Rotation: https://www.hackerrank.com/challenges/array-left-rotation/problem ( Head to folder for more details) +ii. **Left Rotation**: https://www.hackerrank.com/challenges/array-left-rotation/problem ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Left%20Rotation) for more details) -iii. Omkar and Password: https://codeforces.com/problemset/problem/1392/A ( Head to folder for more details) +iii. **Omkar and Password**: https://codeforces.com/problemset/problem/1392/A ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Omkar%20and%20Password) for more details) -iv. Stone: https://codeforces.com/problemset/problem/1236/A ( Head to folder for more details) +iv. **Stone**: https://codeforces.com/problemset/problem/1236/A ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Stone) for more details) -v. Bad Triangle: https://codeforces.com/problemset/problem/1398/A ( Head to folder for more details) +v. **Bad Triangle**: https://codeforces.com/problemset/problem/1398/A ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Bad%20Triangle) for more details) -vi. Chef and Work: https://www.codechef.com/COOK121B/problems/CHEFNWRK ( Head to folder for more details) +vi. **Chef and Work**: https://www.codechef.com/COOK121B/problems/CHEFNWRK ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Chef%20and%20Work) for more details) -vii. Chef and Recipe: https://www.codechef.com/COOK118B/problems/CHEFRECP ( Head to folder for more details) +vii. **Chef and Recipe**: https://www.codechef.com/COOK118B/problems/CHEFRECP ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Chef%20and%20Recipe) for more details) -viii. Three Friends: https://codeforces.com/problemset/problem/1272/A ( Head to folder for more details) +viii. **Three Friends**: https://codeforces.com/problemset/problem/1272/A ( Head to [folder](https://github.com/dsc-iem/IEM-CC-Hacktoberfest/tree/master/Three%20Friends) for more details) `Happy Coding!` :thumbsup: From 28674fc2644048c2ad205cda5715705f18b5c394 Mon Sep 17 00:00:00 2001 From: Girish Garg Date: Wed, 30 Sep 2020 23:03:39 +0530 Subject: [PATCH 07/36] Omkar and Password solved --- Omkar and Password/Omkar and Password.cpp | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Omkar and Password/Omkar and Password.cpp diff --git a/Omkar and Password/Omkar and Password.cpp b/Omkar and Password/Omkar and Password.cpp new file mode 100644 index 0000000..bdfcb1d --- /dev/null +++ b/Omkar and Password/Omkar and Password.cpp @@ -0,0 +1,33 @@ +#include +#define ll long long +using namespace std; + +void solve() { + + int n; cin >> n; + + ll arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + + int count = 0; + + for (int i = 1; i < n; i++) { + if (arr[i] != arr[i - 1]) { + cout << "1" << endl; + return; + } + } + + cout << n << endl; + +} + +int main() { + + int t; cin >> t; + while (t--) { + solve(); + } +} \ No newline at end of file From f96a02f021ee1c6ce336a3b452188f3f0e946e3d Mon Sep 17 00:00:00 2001 From: Divya Prakash Date: Thu, 1 Oct 2020 09:02:23 +0530 Subject: [PATCH 08/36] add chefAndRecipe.cpp --- Chef and Recipe/chefAndRecipe.cpp | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Chef and Recipe/chefAndRecipe.cpp diff --git a/Chef and Recipe/chefAndRecipe.cpp b/Chef and Recipe/chefAndRecipe.cpp new file mode 100644 index 0000000..c24e332 --- /dev/null +++ b/Chef and Recipe/chefAndRecipe.cpp @@ -0,0 +1,78 @@ +#include +using namespace std; + +int main() +{ + int t; + cin >> t; + + while (t--) + { + int n; + cin >> n; + + int a[n]; + for (int i=0; i> a[i]; + + map m, c; + int curr=a[0], count=1, flag=0; + for (int i=1; i Date: Thu, 1 Oct 2020 10:10:55 +0530 Subject: [PATCH 09/36] Left Rotation Solution Added --- Left Rotation/Shovik/Left_Rotation.c | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Left Rotation/Shovik/Left_Rotation.c diff --git a/Left Rotation/Shovik/Left_Rotation.c b/Left Rotation/Shovik/Left_Rotation.c new file mode 100644 index 0000000..7d143d5 --- /dev/null +++ b/Left Rotation/Shovik/Left_Rotation.c @@ -0,0 +1,53 @@ +#include +#include + +struct node{ + int data; + struct node *next; +}; + +struct node *head = NULL, *x, *y, *z; + +void create(int n){ + int c; + if(head==NULL){ + x=(struct node*)malloc(sizeof(struct node)); + x->data=n; + x->next=x; + head=x; + } + else{ + y=(struct node*)malloc(sizeof(struct node)); + y->data=n; + x->next=y; + y->next=head; + x=y; + } +} + +void traverse(){ + x=head; + while(x->next != head){ + printf("%d ", x->data); + x=x->next; + } + printf("%d", x->data); +} + +void leftRotate(){ + head=head->next; +} + +void main() +{ + int n, d, a; + scanf("%d %d", &n, &d); + for(int i=0; i Date: Thu, 1 Oct 2020 10:27:01 +0530 Subject: [PATCH 10/36] added chef and work solution --- Chef and Work/Chef and Work | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Chef and Work/Chef and Work diff --git a/Chef and Work/Chef and Work b/Chef and Work/Chef and Work new file mode 100644 index 0000000..c4acb89 --- /dev/null +++ b/Chef and Work/Chef and Work @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int main() +{ + int testcases; + cin >> testcases; + while (testcases--) { + + int n,k; + cin >> n >> k; + int a[n]; + for(int i=0; i> a[i]; + } + int count = 1; + int sum = 0; + int flag = 0; + for(int i=0; ik) { + cout << "-1" << endl; + flag=1; + break; + } + sum += a[i]; + if(sum > k) { + count++; + sum = a[i]; + } + } + if(flag==0) { + cout << count << endl; + } + } + return 0; +} + From 47f974a1b5f0d91fb9015315f092237907bd6f69 Mon Sep 17 00:00:00 2001 From: manishkheta321 Date: Thu, 1 Oct 2020 16:14:57 +0530 Subject: [PATCH 11/36] solution of Three friends --- Three Friends/Three Friends.cpp | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Three Friends/Three Friends.cpp diff --git a/Three Friends/Three Friends.cpp b/Three Friends/Three Friends.cpp new file mode 100644 index 0000000..fe98215 --- /dev/null +++ b/Three Friends/Three Friends.cpp @@ -0,0 +1,78 @@ +#include + + + +using namespace std; + +/************************Pre processors & typedefs************************/ + +#define pb push_back +#define mp make_pair +#define fr first +#define sc second +#define clr(a) memset(a, 0, sizeof(a)) +#define sz(x) x.size() + +//loop +#define rep(n) for (ll i = 0; i < n; i++) +#define repc(i, n) for (ll i = 0; i < n; i++) +#define FOR(i, x, y) for (int i = x; i < y; i++) +#define DEC(i, x, y) for (int i = x; i >= y; i--) +//for selecting all of a vector or something +#define all(v) v.begin(), v.end() + +#define min3(a, b, c) min(a, min(b, c)) +#define max3(a, b, c) max(a, max(b, c)) + +//all array +#define alla(a, n) a, a + n + +//ignore extra line while taking input +#define clrbuf cin.ignore(numeric_limits::max(),'\n'); + +//precision +#define preciset(x) cout< ii; +typedef vector vi; +typedef vector vii; + + +signed main() +{ + + ll t; + cin>>t; + while(t--){ + ll a,b,c; + cin>>a>>b>>c; + ll ans=1e10; + rep(3) + { + ll x=a+(i-1); + repc(j,3) + { + ll y=b+(j-1); + repc(k,3) + { + ll z=c+(k-1); + ans=min(abs(x-y)+abs(x-z)+abs(z-y),ans); + + + } + } + } + cout< Date: Thu, 1 Oct 2020 07:43:35 -0400 Subject: [PATCH 12/36] Update README.md (#10) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 37cf6b3..d849346 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +#thanks for reading # IEM-CC-Hacktoberfest ![alt text](https://raw.githubusercontent.com/divyake/Cysec-Hacktoberfest/dcc84465cfcff73981f8fcb5c8fe3b1710c007e1/assets/logo.svg) From 0287dff39f91739bc244b4a55c7ce9572cc733eb Mon Sep 17 00:00:00 2001 From: Sayantan Dasgupta <61374798+Arka2001@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:14:23 +0530 Subject: [PATCH 13/36] Dynamic Array Branch (#12) * Created a Python file Dynamic_Array.py for the problem on Dynamic Array * Solution for Dynamic Array Problem using Python --- Dynamic Array/Dynamic_Array.py | 38 +++++++++++++++++++ .../Sayantan_Dasgupta/Dynamic_Array.py | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Dynamic Array/Dynamic_Array.py create mode 100644 Dynamic Array/Sayantan_Dasgupta/Dynamic_Array.py diff --git a/Dynamic Array/Dynamic_Array.py b/Dynamic Array/Dynamic_Array.py new file mode 100644 index 0000000..b01a0a5 --- /dev/null +++ b/Dynamic Array/Dynamic_Array.py @@ -0,0 +1,38 @@ +def dynamicArray(n, queries): #Function Declaration for Dynamic Array taking arguments n=Number of sequences and queries = list of queries for the seqList + lastAnswer = 0 + seqList = [] #Declaring the Empty Sequence List seqList + results = [] #Declaring an empty list for storing the results of the type '2' queries in order of execution + for i in range(n): + seqList.append([]) #Appending the n Empty Sequences in the sequence list seqList + for i in range(len(queries)): #Running a for loop for the necessary functions. The loop runs len(queries) number of times + if(queries[i][0]==1): #If Else statement for checking the condition of type '1' or type '2' Queries + seqList[((queries[i][1]^lastAnswer)%n)].append(queries[i][2]) #Execution statement for type '1' Query + elif(queries[i][0]==2): + seq = seqList[((queries[i][1]^lastAnswer)%n)] #Execution Statements for type '2' Query + size = len(seq) + lastAnswer = seq[queries[i][2]%size] + print(lastAnswer) + results.append(lastAnswer) + return results #Returning the corresponding result of every type '2' query in order of execution + + +n = int(input("\nEnter the number of sequences to be created: ")) +q = int(input("\nEnter the number of queries to be created: ")) + +queries = [] + +for i in range(q): #Creating the Queries List + queries.append([]) + type = int(input("\nEnter the type of query: ")) + queries[i].append(type) + x = int(input("\nEnter integer x for the query: ")) + queries[i].append(x) + y = int(input("\nEnter integer y for the query: ")) + queries[i].append(y) + +result = dynamicArray(n,queries) #Calling the function dynamicArray +print("\nResult of the type 2 queries in order of execution is: ",result) + + + + diff --git a/Dynamic Array/Sayantan_Dasgupta/Dynamic_Array.py b/Dynamic Array/Sayantan_Dasgupta/Dynamic_Array.py new file mode 100644 index 0000000..b01a0a5 --- /dev/null +++ b/Dynamic Array/Sayantan_Dasgupta/Dynamic_Array.py @@ -0,0 +1,38 @@ +def dynamicArray(n, queries): #Function Declaration for Dynamic Array taking arguments n=Number of sequences and queries = list of queries for the seqList + lastAnswer = 0 + seqList = [] #Declaring the Empty Sequence List seqList + results = [] #Declaring an empty list for storing the results of the type '2' queries in order of execution + for i in range(n): + seqList.append([]) #Appending the n Empty Sequences in the sequence list seqList + for i in range(len(queries)): #Running a for loop for the necessary functions. The loop runs len(queries) number of times + if(queries[i][0]==1): #If Else statement for checking the condition of type '1' or type '2' Queries + seqList[((queries[i][1]^lastAnswer)%n)].append(queries[i][2]) #Execution statement for type '1' Query + elif(queries[i][0]==2): + seq = seqList[((queries[i][1]^lastAnswer)%n)] #Execution Statements for type '2' Query + size = len(seq) + lastAnswer = seq[queries[i][2]%size] + print(lastAnswer) + results.append(lastAnswer) + return results #Returning the corresponding result of every type '2' query in order of execution + + +n = int(input("\nEnter the number of sequences to be created: ")) +q = int(input("\nEnter the number of queries to be created: ")) + +queries = [] + +for i in range(q): #Creating the Queries List + queries.append([]) + type = int(input("\nEnter the type of query: ")) + queries[i].append(type) + x = int(input("\nEnter integer x for the query: ")) + queries[i].append(x) + y = int(input("\nEnter integer y for the query: ")) + queries[i].append(y) + +result = dynamicArray(n,queries) #Calling the function dynamicArray +print("\nResult of the type 2 queries in order of execution is: ",result) + + + + From d543852efaf7f86172e6be401ea7424fc5042de2 Mon Sep 17 00:00:00 2001 From: Muskan Jain Date: Thu, 1 Oct 2020 17:15:01 +0530 Subject: [PATCH 14/36] Solution for Dynami Array in Python (#9) --- Dynamic Array/dynamic_array_muskanapp.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Dynamic Array/dynamic_array_muskanapp.py diff --git a/Dynamic Array/dynamic_array_muskanapp.py b/Dynamic Array/dynamic_array_muskanapp.py new file mode 100644 index 0000000..7841db8 --- /dev/null +++ b/Dynamic Array/dynamic_array_muskanapp.py @@ -0,0 +1,16 @@ +#This code is contributed by github user muskanapp + +N, Q = map( int, input().split() ) #taking input +lastans = 0 #initialise a variable lastans to 0 + +seqList = [ [] for _ in range( N ) ] #creating a list seqList of n empty sequences +#performing the queries on seqList +for _ in range( Q ): + t, x, y = map( int, input().split() ) + if t == 1: #query 1 + seqList[ ( x ^ lastans ) % N ].append( y ) + elif t == 2: #query 2 + arr = seqList[ ( x ^ lastans ) % N ] + val = arr[ y % len(arr) ] + print( val ) + lastans = val \ No newline at end of file From a95be9bdf6aea5a0707b53731ac7b6eaf5e10a7a Mon Sep 17 00:00:00 2001 From: Muskan Jain Date: Thu, 1 Oct 2020 17:15:25 +0530 Subject: [PATCH 15/36] Added solution for Dynamic Array in Python (#5) From 3e6792b0ef4a3eba7c25e2120bd93137a6db299f Mon Sep 17 00:00:00 2001 From: manishkheta321 Date: Thu, 1 Oct 2020 18:11:22 +0530 Subject: [PATCH 16/36] Bad Triangle Solution --- Bad Triangle/Bad Triangle.cpp | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Bad Triangle/Bad Triangle.cpp diff --git a/Bad Triangle/Bad Triangle.cpp b/Bad Triangle/Bad Triangle.cpp new file mode 100644 index 0000000..959615d --- /dev/null +++ b/Bad Triangle/Bad Triangle.cpp @@ -0,0 +1,57 @@ +#include + + + +using namespace std; + +/************************Pre processors & typedefs************************/ + +#define pb push_back +#define mp make_pair +#define fr first +#define sc second +#define clr(a) memset(a, 0, sizeof(a)) +#define sz(x) x.size() + +//loop +#define rep(n) for (ll i = 0; i < n; i++) + +// datatypes +typedef long long ll; + + +signed main() +{ + + ll t; + cin>>t; + while(t--){ + + ll n; + cin>>n; + ll a[n]; + rep(n) + cin>>a[i]; + ll f=0; + for(ll i=2;i Date: Thu, 1 Oct 2020 18:32:21 +0530 Subject: [PATCH 17/36] Three-Friends-Solution --- Three Friends/Three-Friends-Sol.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Three Friends/Three-Friends-Sol.cpp diff --git a/Three Friends/Three-Friends-Sol.cpp b/Three Friends/Three-Friends-Sol.cpp new file mode 100644 index 0000000..76b7ba1 --- /dev/null +++ b/Three Friends/Three-Friends-Sol.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +typedef long long ll; +int main(){ + int q; + cin >> q; + while(q--){ + ll a, b, c; + cin >> a >> b >> c; + ll result = abs(a-b) + abs(b-c) + abs(c-a); + ll ca, cb, cc; + for(ll i=-1 ; i<=1 ; i++){ + for(ll j=-1 ; j<=1 ; j++){ + for(ll k=-1 ; k<=1 ; k++){ + ca = a + i; + cb = b + j; + cc = c + k; + result = min(abs(ca-cb) + abs(ca-cc) + abs(cb-cc), result); + } + } + } + cout< Date: Thu, 1 Oct 2020 23:40:13 +0530 Subject: [PATCH 18/36] Create tushargit --- Left Rotation/tushargit | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Left Rotation/tushargit diff --git a/Left Rotation/tushargit b/Left Rotation/tushargit new file mode 100644 index 0000000..1e34b9e --- /dev/null +++ b/Left Rotation/tushargit @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main(){ + int n,d; + cin >> n >> d; + vectora; + for(int i=0;i> x; + a.push_back(x); + } + for(int i=d;i Date: Fri, 2 Oct 2020 02:21:21 +0530 Subject: [PATCH 19/36] Solved Stones Problem --- Stone/Tanmay.java | 154 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Stone/Tanmay.java diff --git a/Stone/Tanmay.java b/Stone/Tanmay.java new file mode 100644 index 0000000..890d7da --- /dev/null +++ b/Stone/Tanmay.java @@ -0,0 +1,154 @@ +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class Tanmay +{ + static class Reader + { + final private int BUFFER_SIZE = 1 << 16; + private DataInputStream din; + private byte[] buffer; + private int bufferPointer, bytesRead; + + public Reader() + { + din = new DataInputStream(System.in); + buffer = new byte[BUFFER_SIZE]; + bufferPointer = bytesRead = 0; + } + + public Reader(String file_name) throws IOException + { + din = new DataInputStream(new FileInputStream(file_name)); + buffer = new byte[BUFFER_SIZE]; + bufferPointer = bytesRead = 0; + } + + public String readLine() throws IOException + { + byte[] buf = new byte[64]; // line length + int cnt = 0, c; + while ((c = read()) != -1) + { + if (c == '\n') + break; + buf[cnt++] = (byte) c; + } + return new String(buf, 0, cnt); + } + + public int nextInt() throws IOException + { + int ret = 0; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + do + { + ret = ret * 10 + c - '0'; + } while ((c = read()) >= '0' && c <= '9'); + + if (neg) + return -ret; + return ret; + } + + public long nextLong() throws IOException + { + long ret = 0; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + do { + ret = ret * 10 + c - '0'; + } + while ((c = read()) >= '0' && c <= '9'); + if (neg) + return -ret; + return ret; + } + + public double nextDouble() throws IOException + { + double ret = 0, div = 1; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + + do { + ret = ret * 10 + c - '0'; + } + while ((c = read()) >= '0' && c <= '9'); + + if (c == '.') + { + while ((c = read()) >= '0' && c <= '9') + { + ret += (c - '0') / (div *= 10); + } + } + + if (neg) + return -ret; + return ret; + } + + private void fillBuffer() throws IOException + { + bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); + if (bytesRead == -1) + buffer[0] = -1; + } + + private byte read() throws IOException + { + if (bufferPointer == bytesRead) + fillBuffer(); + return buffer[bufferPointer++]; + } + + public void close() throws IOException + { + if (din == null) + return; + din.close(); + } + } + + public static void main(String[] args) throws IOException + { + Reader s=new Reader(); + int n = s.nextInt(); + while (n-- > 0) + { + int a,b,c,result = 0; + a = s.nextInt(); + b = s.nextInt(); + c = s.nextInt(); + int MIN = Math.min(b,c/2); + if(MIN>0){ + result += MIN*3; + b -= MIN; + } + MIN = Math.min(a, b/2); + if(MIN > 0) { + result += (3 * MIN); + } + System.out.println(result); + } + + } +} From 1fff75ba9f83c9cad0c33c0e34587bd443c0eb53 Mon Sep 17 00:00:00 2001 From: Divya Prakash Date: Fri, 2 Oct 2020 09:26:17 +0530 Subject: [PATCH 20/36] add chefAndRecipe.java --- Chef and Recipe/chefAndRecipe.java | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Chef and Recipe/chefAndRecipe.java diff --git a/Chef and Recipe/chefAndRecipe.java b/Chef and Recipe/chefAndRecipe.java new file mode 100644 index 0000000..86994c3 --- /dev/null +++ b/Chef and Recipe/chefAndRecipe.java @@ -0,0 +1,87 @@ + +import java.util.*; +import java.lang.*; +import java.io.*; + + +class chefAndRecipe +{ + public static void main (String[] args) + { + + Scanner sc=new Scanner(System.in); + int T=sc.nextInt(); + while(T-->0) + { + int N=sc.nextInt(); + int[] A=new int[N]; + int[] B=new int[N]; + int[] C=new int[N]; + int i=0; + for(int s=0;s=1;m--) + { + if(B[m]!=0 && B[m-1]!=0) + { + if(B[m]==B[m-1]) + { + y=1; + break; + } + } + } + + if(y==1) + { + System.out.println("NO"); + } + else + { + for(int m=N-1;m>=1;m--) + { + if(C[m]!=0 && C[m-1]!=0) + { + if(C[m]==C[m-1]) + { + g=1; + break; + } + } + } + if(g==1) + System.out.println("NO"); + else + System.out.println("YES"); + } + } + } +} From efddc1866a5b9d8a9a435264d425136282498394 Mon Sep 17 00:00:00 2001 From: 7sparsh Date: Fri, 2 Oct 2020 11:03:38 +0530 Subject: [PATCH 21/36] Added Solution for Dynamic Array problem --- .../Sparsh_Saxena/dynamicArray_hackerrank.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Dynamic Array/Sparsh_Saxena/dynamicArray_hackerrank.cpp diff --git a/Dynamic Array/Sparsh_Saxena/dynamicArray_hackerrank.cpp b/Dynamic Array/Sparsh_Saxena/dynamicArray_hackerrank.cpp new file mode 100644 index 0000000..5a4dc67 --- /dev/null +++ b/Dynamic Array/Sparsh_Saxena/dynamicArray_hackerrank.cpp @@ -0,0 +1,28 @@ +#include +#define ll long long int +#define endl '\n' +using namespace std; + +int main(){ + + ll n,q; + cin >> n >> q; + vectorseqList[n]; + ll lastAns = 0; + for(ll i=0;i> ch >> x >> y; + ll pos = (x^lastAns)%n; + if(ch==1) { + seqList[pos].push_back(y); + } + else if(ch==2){ + ll index = y%((ll)seqList[pos].size()); + lastAns = seqList[pos][index]; + cout << lastAns << endl; + } + } + return 0; +} + + From c6b96d6b8937161237119242518ca2e91f8d52f0 Mon Sep 17 00:00:00 2001 From: the-agarwal01 Date: Fri, 2 Oct 2020 11:54:04 +0530 Subject: [PATCH 22/36] This is the slution for left rotation problem --- Left Rotation/tushargithub/left roation.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Left Rotation/tushargithub/left roation.cpp diff --git a/Left Rotation/tushargithub/left roation.cpp b/Left Rotation/tushargithub/left roation.cpp new file mode 100644 index 0000000..1e34b9e --- /dev/null +++ b/Left Rotation/tushargithub/left roation.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main(){ + int n,d; + cin >> n >> d; + vectora; + for(int i=0;i> x; + a.push_back(x); + } + for(int i=d;i Date: Sun, 4 Oct 2020 14:56:01 +0530 Subject: [PATCH 23/36] Added few Added few --- Left Rotation/left_rotation.py | 14 ++++++++++++++ Stone/1236A.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 Left Rotation/left_rotation.py create mode 100644 Stone/1236A.py diff --git a/Left Rotation/left_rotation.py b/Left Rotation/left_rotation.py new file mode 100644 index 0000000..bd63dc8 --- /dev/null +++ b/Left Rotation/left_rotation.py @@ -0,0 +1,14 @@ +import sys + +def In(): + return sys.stdin.readline() + +def Out(x): + return sys.stdout.write(str(x)+'\n') + + +n,d=map(int,In().split()) +arr=list(map(str,In().split())) +d=d%n +ans=arr[d:]+arr[:d] +Out(' '.join(ans)) diff --git a/Stone/1236A.py b/Stone/1236A.py new file mode 100644 index 0000000..86fcd17 --- /dev/null +++ b/Stone/1236A.py @@ -0,0 +1,28 @@ +import sys + +def In(): + return sys.stdin.readline() + +def Out(x): + return sys.stdout.write(str(x)+'\n') + + +def Solve(arr): + count=0 + obj1=min(arr[1],arr[2]//2) + count+=obj1*3 + arr[1]=arr[1]-obj1 + arr[2]=arr[2]-obj1*2 + obj2=min(arr[0],arr[1]//2) + count+=obj2*3 + arr[0]=arr[0]-obj2 + arr[1]=arr[1]-obj2*2 + return count + + + + +t=int(In()) +for i in range(t): + arr=list(map(int,In().split())) + Out(Solve(arr)) From 32ca04a87db885a8a905de010960fe261cd2f733 Mon Sep 17 00:00:00 2001 From: digiashhar <65493417+digiashhar@users.noreply.github.com> Date: Sun, 4 Oct 2020 21:43:56 +0530 Subject: [PATCH 24/36] Create AshharCode --- Chef and Work/AshharCode | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Chef and Work/AshharCode diff --git a/Chef and Work/AshharCode b/Chef and Work/AshharCode new file mode 100644 index 0000000..2ee6434 --- /dev/null +++ b/Chef and Work/AshharCode @@ -0,0 +1,20 @@ +#include +using namespace std; +int main() +{long t; cin>>t; +while(t--) +{long n,k,m,c=0; cin>>n>>k; m=k; +vectorv(n); bool b=true; +for(long i=0;i>v[i];if(v[i]>k){b=false;}} +if(b){ +for(long i=0;i Date: Sun, 4 Oct 2020 22:01:39 +0530 Subject: [PATCH 25/36] Create chefandRecipeec++ --- Chef and Recipe/chefandRecipeec++ | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Chef and Recipe/chefandRecipeec++ diff --git a/Chef and Recipe/chefandRecipeec++ b/Chef and Recipe/chefandRecipeec++ new file mode 100644 index 0000000..c6e6b96 --- /dev/null +++ b/Chef and Recipe/chefandRecipeec++ @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define modulus 1000000007 +using namespace std; + +int n; +vector arr(1005), cnt(1005, 0); +unordered_set uset; + +void f(){ + int i = 0; + bool ok = true; + while(i < n && ok){ + if(cnt[arr[i]] > 0){ + // cout << 1 << endl; + ok = false; + break; + } + int j = i; + while(j < n && arr[j] == arr[i]) j++; + int tot = j - i; + if(uset.find(tot) != uset.end()){ + // cout << 2 << endl; + ok = false; + break; + } + cnt[arr[i]] = tot; + uset.insert(tot); + i = j; + } + if(ok) cout << "YES" << endl; + else cout << "NO" << endl; +} + +int main(){ + int t; + cin >> t; + while(t--){ + cin >> n; + for(int i = 0; i < n; i++) cin >> arr[i]; + f(); + for(int i = 0; i < cnt.size(); i++) cnt[i] = 0; + uset.clear(); + } +} From 3c9ba61177031eef1935fa74cd76d76a4ef48832 Mon Sep 17 00:00:00 2001 From: diksha0399 Date: Tue, 6 Oct 2020 17:59:03 +0530 Subject: [PATCH 26/36] updated code --- .../Diksha Dixit/ChefRecipeSolution.java | 69 +++++++++++++++ .../Diksha Dixit/DynamicArraySolution.java | 86 +++++++++++++++++++ .../Diksha Dixit/LeftRotationSolution.java | 41 +++++++++ Stone/Diksha Dixit/StonesSolution.java | 30 +++++++ 4 files changed, 226 insertions(+) create mode 100644 Chef and Recipe/Diksha Dixit/ChefRecipeSolution.java create mode 100644 Dynamic Array/Diksha Dixit/DynamicArraySolution.java create mode 100644 Left Rotation/Diksha Dixit/LeftRotationSolution.java create mode 100644 Stone/Diksha Dixit/StonesSolution.java diff --git a/Chef and Recipe/Diksha Dixit/ChefRecipeSolution.java b/Chef and Recipe/Diksha Dixit/ChefRecipeSolution.java new file mode 100644 index 0000000..45522ee --- /dev/null +++ b/Chef and Recipe/Diksha Dixit/ChefRecipeSolution.java @@ -0,0 +1,69 @@ +package codechef; + +import java.util.Arrays; +import java.util.Scanner; + +public class ChefRecipeSolution { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + while (T-- > 0) { + int N = sc.nextInt(); + int[] A = new int[N]; + int[] B = new int[N]; + int[] C = new int[N]; + int i = 0; + for (int s = 0; s < N; s++) { + A[s] = sc.nextInt(); + } + int k = 1, t = 0; + for (i = 1; i < N; i++) { + if (A[i] == A[i - 1]) + k++; + else { + B[t] = A[i - 1]; + C[t] = k; + t++; + k = 1; + } + } + B[t] = A[i - 1]; + C[t] = k; + t++; + + Arrays.sort(B); + Arrays.sort(C); + + int y = 0, g = 0; + for (int m = N - 1; m >= 1; m--) { + if (B[m] != 0 && B[m - 1] != 0) { + if (B[m] == B[m - 1]) { + y = 1; + break; + } + } + } + + if (y == 1) { + System.out.println("NO"); + } else { + for (int m = N - 1; m >= 1; m--) { + if (C[m] != 0 && C[m - 1] != 0) { + if (C[m] == C[m - 1]) { + g = 1; + break; + } + } + } + if (g == 1) + System.out.println("NO"); + else + System.out.println("YES"); + } + } + sc.close(); + } + +} diff --git a/Dynamic Array/Diksha Dixit/DynamicArraySolution.java b/Dynamic Array/Diksha Dixit/DynamicArraySolution.java new file mode 100644 index 0000000..1429f5d --- /dev/null +++ b/Dynamic Array/Diksha Dixit/DynamicArraySolution.java @@ -0,0 +1,86 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.function.*; +import java.util.regex.*; +import java.util.stream.*; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + +class Result { + + /* + * Complete the 'dynamicArray' function below. + * + * The function is expected to return an INTEGER_ARRAY. + * The function accepts following parameters: + * 1. INTEGER n + * 2. 2D_INTEGER_ARRAY queries + */ + + public static List dynamicArray(int n, List> queries) { + // Write your code here + ArrayList> seqList= new ArrayList<>(); + ArrayList result=new ArrayList<>(); + for(int i=0;i()); + int lastAnswer=0; + for(int i=0;i query=queries.get(i); + if(query.get(0)==1){ + int index=(query.get(1)^lastAnswer)%n; + ArrayList seq= seqList.get(index); + seq.add(query.get(2)); + } + else{ + int index=(query.get(1)^lastAnswer)%n; + ArrayList seq= seqList.get(index); + lastAnswer=seq.get(query.get(2)%seq.size()); + result.add(lastAnswer); + } + } + return result; +} +} + +public class DynamicArraySolution { + public static void main(String[] args) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); + + String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); + + int n = Integer.parseInt(firstMultipleInput[0]); + + int q = Integer.parseInt(firstMultipleInput[1]); + + List> queries = new ArrayList<>(); + + IntStream.range(0, q).forEach(i -> { + try { + queries.add( + Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) + .map(Integer::parseInt) + .collect(toList()) + ); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + + List result = Result.dynamicArray(n, queries); + + bufferedWriter.write( + result.stream() + .map(Object::toString) + .collect(joining("\n")) + + "\n" + ); + + bufferedReader.close(); + bufferedWriter.close(); + } +} diff --git a/Left Rotation/Diksha Dixit/LeftRotationSolution.java b/Left Rotation/Diksha Dixit/LeftRotationSolution.java new file mode 100644 index 0000000..be512bd --- /dev/null +++ b/Left Rotation/Diksha Dixit/LeftRotationSolution.java @@ -0,0 +1,41 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.regex.*; + +public class LeftRotationSolution { + + + + private static final Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + String[] nd = scanner.nextLine().split(" "); + + int n = Integer.parseInt(nd[0]); + + int d = Integer.parseInt(nd[1]); + + int[] a = new int[n]; + + String[] aItems = scanner.nextLine().split(" "); + scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); + + for (int i = 0; i < n; i++) { + int aItem = Integer.parseInt(aItems[i]); + a[i] = aItem; + } + int[] rotated= new int[n]; + for(int i=0,pos=n-d;i 0) { + int a, b, c, result = 0; + a = s.nextInt(); + b = s.nextInt(); + c = s.nextInt(); + int MIN = Math.min(b, c / 2); + if (MIN > 0) { + result += MIN * 3; + b -= MIN; + } + MIN = Math.min(a, b / 2); + if (MIN > 0) { + result += (3 * MIN); + } + System.out.println(result); + } + s.close(); + } + +} \ No newline at end of file From 9faf2bf89a00249be9a3979214cf4b4d47b6369b Mon Sep 17 00:00:00 2001 From: imKashyap Date: Tue, 6 Oct 2020 18:10:48 +0530 Subject: [PATCH 27/36] Added programs --- .../Rahul_Kashyap/DynamicArraySolution.java | 86 +++++++++++++++++++ .../Rahul_Kashyap/LeftRotationSolution.java | 41 +++++++++ 2 files changed, 127 insertions(+) create mode 100644 Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java create mode 100644 Left Rotation/Rahul_Kashyap/LeftRotationSolution.java diff --git a/Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java b/Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java new file mode 100644 index 0000000..67d938d --- /dev/null +++ b/Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java @@ -0,0 +1,86 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.function.*; +import java.util.regex.*; +import java.util.stream.*; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + +class Result { + + /* + * Complete the 'dynamicArray' function below. + * + * The function is expected to return an INTEGER_ARRAY. + * The function accepts following parameters: + * 1. INTEGER n + * 2. 2D_INTEGER_ARRAY queries + */ + + public static List dynamicArray(int n, List> queries) { + // Write your code here + ArrayList> seqList= new ArrayList<>(); + ArrayList result=new ArrayList<>(); + for(int i=0;i()); + int lastAnswer=0; + for(int i=0;i query=queries.get(i); + if(query.get(0)==1){ + int index=(query.get(1)^lastAnswer)%n; + ArrayList seq= seqList.get(index); + seq.add(query.get(2)); + } + else{ + int index=(query.get(1)^lastAnswer)%n; + ArrayList seq= seqList.get(index); + lastAnswer=seq.get(query.get(2)%seq.size()); + result.add(lastAnswer); + } + } + return result; +} +} + +public class DynamicArraySolution { + public static void main(String[] args) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); + + String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); + + int n = Integer.parseInt(firstMultipleInput[0]); + + int q = Integer.parseInt(firstMultipleInput[1]); + + List> queries = new ArrayList<>(); + + IntStream.range(0, q).forEach(i -> { + try { + queries.add( + Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) + .map(Integer::parseInt) + .collect(toList()) + ); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + + List result = Result.dynamicArray(n, queries); + + bufferedWriter.write( + result.stream() + .map(Object::toString) + .collect(joining("\n")) + + "\n" + ); + + bufferedReader.close(); + bufferedWriter.close(); + } +} diff --git a/Left Rotation/Rahul_Kashyap/LeftRotationSolution.java b/Left Rotation/Rahul_Kashyap/LeftRotationSolution.java new file mode 100644 index 0000000..d334bc8 --- /dev/null +++ b/Left Rotation/Rahul_Kashyap/LeftRotationSolution.java @@ -0,0 +1,41 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.regex.*; + +public class LeftRotationSolution { + + + + private static final Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + String[] nd = scanner.nextLine().split(" "); + + int n = Integer.parseInt(nd[0]); + + int d = Integer.parseInt(nd[1]); + + int[] a = new int[n]; + + String[] aItems = scanner.nextLine().split(" "); + scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); + + for (int i = 0; i < n; i++) { + int aItem = Integer.parseInt(aItems[i]); + a[i] = aItem; + } + int[] rotated= new int[n]; + for(int i=0,pos=n-d;i Date: Wed, 7 Oct 2020 01:04:30 +0530 Subject: [PATCH 28/36] Solution added Left Rotation --- Left Rotation/mohini/solution.cpp | 102 ++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Left Rotation/mohini/solution.cpp diff --git a/Left Rotation/mohini/solution.cpp b/Left Rotation/mohini/solution.cpp new file mode 100644 index 0000000..b30df18 --- /dev/null +++ b/Left Rotation/mohini/solution.cpp @@ -0,0 +1,102 @@ +#include + +using namespace std; + +string ltrim(const string &); +string rtrim(const string &); +vector split(const string &); + +vector rotateLeft(int d, vector a) { + int l=a.size(); + int i; + vector b(l); + for(i=0;i first_multiple_input = split(rtrim(first_multiple_input_temp)); + + int n = stoi(first_multiple_input[0]); + + int d = stoi(first_multiple_input[1]); + + string arr_temp_temp; + getline(cin, arr_temp_temp); + + vector arr_temp = split(rtrim(arr_temp_temp)); + + vector arr(n); + + for (int i = 0; i < n; i++) { + int arr_item = stoi(arr_temp[i]); + + arr[i] = arr_item; + } + + vector result = rotateLeft(d, arr); + + for (int i = 0; i < result.size(); i++) { + fout << result[i]; + + if (i != result.size() - 1) { + fout << " "; + } + } + + fout << "\n"; + + fout.close(); + + return 0; +} + +string ltrim(const string &str) { + string s(str); + + s.erase( + s.begin(), + find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) + ); + + return s; +} + +string rtrim(const string &str) { + string s(str); + + s.erase( + find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), + s.end() + ); + + return s; +} + +vector split(const string &str) { + vector tokens; + + string::size_type start = 0; + string::size_type end = 0; + + while ((end = str.find(" ", start)) != string::npos) { + tokens.push_back(str.substr(start, end - start)); + + start = end + 1; + } + + tokens.push_back(str.substr(start)); + + return tokens; +} From 89f47994debb10a7f6a73844402c277928444d57 Mon Sep 17 00:00:00 2001 From: Shrey2002 <72299720+Shrey2002@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:52:30 +0530 Subject: [PATCH 29/36] Create Readme.md --- Attribute Parser/Readme.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Attribute Parser/Readme.md diff --git a/Attribute Parser/Readme.md b/Attribute Parser/Readme.md new file mode 100644 index 0000000..edebfdf --- /dev/null +++ b/Attribute Parser/Readme.md @@ -0,0 +1,23 @@ +## Attribute Parser + +Problem Link: https://www.hackerrank.com/challenges/attribute-parser/problem + +This challenge works with a custom-designed markup language HRML. + +In HRML, each element consists of a starting and ending tag, and there are attributes associated with each tag. + +Only starting tags can have attributes. We can call an attribute by referencing the tag, followed by a tilde, '~' and the name of the attribute. + +The tags may also be nested.The opening tags follow the format: + + + +The attributes are referenced as: + +tag1~value + +tag1.tag2~name + +Given the source code in HRML format consisting of lines, answer queries. For each query, print the value of the attribute specified. + +Print "Not Found!" if the attribute does not exist. From 25bf7958dc250c1a23edb30571bde5dde2089243 Mon Sep 17 00:00:00 2001 From: Shrey2002 <72299720+Shrey2002@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:53:38 +0530 Subject: [PATCH 30/36] Create Solution.cpp --- Attribute Parser/Solution.cpp | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Attribute Parser/Solution.cpp diff --git a/Attribute Parser/Solution.cpp b/Attribute Parser/Solution.cpp new file mode 100644 index 0000000..7a6c520 --- /dev/null +++ b/Attribute Parser/Solution.cpp @@ -0,0 +1,58 @@ +#include +#include +using namespace std; + +map tagMap; + +void createMap(int &n, string pretag) { + if(!n) return; + + string line, tag, attr, value; + getline(cin, line); + + int i=1; + if(line[i]=='/') { // found closing tag + while(line[i]!='>') i++; + if(pretag.size()>(i-2)) // update tag + tag = pretag.substr(0,pretag.size()-i+1); + else + tag = ""; + } + else { // found opening tag + while(line[i]!=' ' && line[i]!='>') i++; + tag = line.substr(1,i-1); // update tag + if(pretag!="") tag = pretag + "." + tag; + + int j; + while(line[i]!='>') { // go through attributes + j = ++i; + while(line[i]!=' ') i++; + attr = line.substr(j,i-j); // attribute name + + while(line[i]!='\"') i++; + j = ++i; + while(line[i]!='\"') i++; + value = line.substr(j,i-j); // attribute value + i+= 1; + + tagMap[tag + "~" + attr] = value; + } + } + createMap(--n, tag); +} + +int main() { + int n, q; + cin >> n >> q; + cin.ignore(); + createMap(n,""); + + string attr, value; + while(q--) { + getline(cin,attr); + value = tagMap[attr]; + if(value=="") value = "Not Found!"; + cout << value << endl; + } + return 0; +} From ef64461d3f4aff1c3b47a89023bba4e6dd56e1a5 Mon Sep 17 00:00:00 2001 From: Mohinig Date: Wed, 7 Oct 2020 12:04:17 +0530 Subject: [PATCH 31/36] Dynamic array solution added --- Dynamic Array/mohini/solution.cpp | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Dynamic Array/mohini/solution.cpp diff --git a/Dynamic Array/mohini/solution.cpp b/Dynamic Array/mohini/solution.cpp new file mode 100644 index 0000000..750e7ba --- /dev/null +++ b/Dynamic Array/mohini/solution.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +int main() +{ + int n, q, last_ans = 0, x, y; + int op, ans; + + cin >> n >> q; + vector > arr(n); + + while (q--) { + + cin >> op >> x >> y; + + switch (op) { + case 1 : + { + arr[(x ^ last_ans) % n].push_back(y); + break; + } + case 2: + { + ans = arr[(x ^ last_ans) % n][y % arr[(x ^ last_ans) % n].size()]; + last_ans = ans; + cout << ans << endl; + break; + } + } + } + + return 0; +} \ No newline at end of file From 246b9c5b6e2ee45a007b1153b0b1aad911107991 Mon Sep 17 00:00:00 2001 From: imKashyap Date: Wed, 7 Oct 2020 18:02:37 +0530 Subject: [PATCH 32/36] Added some program solutions --- .../Rahul Kashyap/ChefAndRecipeSolution.java | 50 +++++++++++++++++++ .../Rahul Kashyap/ChefAndWorkSolution.java | 38 ++++++++++++++ .../DynamicArraySolution.java | 0 .../LeftRotationSolution.java | 0 Stone/Rahul Kashyap/StoneSolution.java | 26 ++++++++++ 5 files changed, 114 insertions(+) create mode 100644 Chef and Recipe/Rahul Kashyap/ChefAndRecipeSolution.java create mode 100644 Chef and Work/Rahul Kashyap/ChefAndWorkSolution.java rename Dynamic Array/{Rahul_Kashyap => Rahul Kashyap}/DynamicArraySolution.java (100%) rename Left Rotation/{Rahul_Kashyap => Rahul Kashyap}/LeftRotationSolution.java (100%) create mode 100644 Stone/Rahul Kashyap/StoneSolution.java diff --git a/Chef and Recipe/Rahul Kashyap/ChefAndRecipeSolution.java b/Chef and Recipe/Rahul Kashyap/ChefAndRecipeSolution.java new file mode 100644 index 0000000..0d70e29 --- /dev/null +++ b/Chef and Recipe/Rahul Kashyap/ChefAndRecipeSolution.java @@ -0,0 +1,50 @@ +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +public class ChefAndRecipeSolution { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int T = sc.nextInt(); + for (int tc = 0; tc < T; ++tc) { + int N = sc.nextInt(); + int[] A = new int[N]; + for (int i = 0; i < A.length; ++i) { + A[i] = sc.nextInt(); + } + + System.out.println(solve(A) ? "YES" : "NO"); + } + + sc.close(); + } + + static boolean solve(int[] A) { + Set values = new HashSet<>(); + Set counts = new HashSet<>(); + int value = -1; + int count = -1; + for (int i = 0; i <= A.length; ++i) { + if (i != A.length && A[i] == value) { + ++count; + } else { + if (value != -1) { + if (values.contains(value) || counts.contains(count)) { + return false; + } + + values.add(value); + counts.add(count); + } + + if (i != A.length) { + value = A[i]; + count = 1; + } + } + } + + return true; + } +} \ No newline at end of file diff --git a/Chef and Work/Rahul Kashyap/ChefAndWorkSolution.java b/Chef and Work/Rahul Kashyap/ChefAndWorkSolution.java new file mode 100644 index 0000000..6c884ca --- /dev/null +++ b/Chef and Work/Rahul Kashyap/ChefAndWorkSolution.java @@ -0,0 +1,38 @@ +import java.util.Scanner; + +public class ChefAndWorkSolution { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int T = sc.nextInt(); + for (int tc = 0; tc < T; ++tc) { + int N = sc.nextInt(); + int K = sc.nextInt(); + int[] W = new int[N]; + for (int i = 0; i < W.length; ++i) { + W[i] = sc.nextInt(); + } + + System.out.println(solve(W, K)); + } + + sc.close(); + } + + static int solve(int[] W, int K) { + int result = 1; + int remain = K; + for (int Wi : W) { + if (Wi <= remain) { + remain -= Wi; + } else if (Wi <= K) { + ++result; + remain = K - Wi; + } else { + return -1; + } + } + + return result; + } +} \ No newline at end of file diff --git a/Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java b/Dynamic Array/Rahul Kashyap/DynamicArraySolution.java similarity index 100% rename from Dynamic Array/Rahul_Kashyap/DynamicArraySolution.java rename to Dynamic Array/Rahul Kashyap/DynamicArraySolution.java diff --git a/Left Rotation/Rahul_Kashyap/LeftRotationSolution.java b/Left Rotation/Rahul Kashyap/LeftRotationSolution.java similarity index 100% rename from Left Rotation/Rahul_Kashyap/LeftRotationSolution.java rename to Left Rotation/Rahul Kashyap/LeftRotationSolution.java diff --git a/Stone/Rahul Kashyap/StoneSolution.java b/Stone/Rahul Kashyap/StoneSolution.java new file mode 100644 index 0000000..9f53295 --- /dev/null +++ b/Stone/Rahul Kashyap/StoneSolution.java @@ -0,0 +1,26 @@ +import java.util.*; + +public class StoneSolution { + public static void main(String[] args) throws IOException { + Scanner s=new Scanner(); + int n = s.nextInt(); + while (n-- > 0) + { + int a,b,c,result = 0; + a = s.nextInt(); + b = s.nextInt(); + c = s.nextInt(); + int MIN = Math.min(b,c/2); + if(MIN>0){ + result += MIN*3; + b -= MIN; + } + MIN = Math.min(a, b/2); + if(MIN > 0) { + result += (3 * MIN); + } + System.out.println(result); + } + + } +} \ No newline at end of file From 040c24ec8517f74f93965b46980a2b69f739703f Mon Sep 17 00:00:00 2001 From: Ritwik Singh <46321538+ritwiksingh21@users.noreply.github.com> Date: Thu, 8 Oct 2020 09:36:18 +0530 Subject: [PATCH 33/36] Stones problem sol. in C --- Stone/Sol_Stones_C | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Stone/Sol_Stones_C diff --git a/Stone/Sol_Stones_C b/Stone/Sol_Stones_C new file mode 100644 index 0000000..8b74e52 --- /dev/null +++ b/Stone/Sol_Stones_C @@ -0,0 +1,19 @@ +#include + +int main() +{ + int a,b,c,ans,t; + scanf("%d", &t); + while(t--){ + ans=0; + scanf("%d %d %d", &a, &b, &c); + while(b>=1 && c>=2){ + b-=1; c-=2; ans+=3; + } + while(a>=1 && b>=2){ + a-=1; b-=2; ans+=3; + } + printf("%d\n", ans); + } + return 0; +} From a29421192f84cc47bd4d5e193b8f97cce30956c9 Mon Sep 17 00:00:00 2001 From: Nidhi Singh Date: Thu, 8 Oct 2020 14:01:28 +0530 Subject: [PATCH 34/36] left rotation in python added --- Left Rotation/nidhi/left rotation.py | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Left Rotation/nidhi/left rotation.py diff --git a/Left Rotation/nidhi/left rotation.py b/Left Rotation/nidhi/left rotation.py new file mode 100644 index 0000000..5a8bb0b --- /dev/null +++ b/Left Rotation/nidhi/left rotation.py @@ -0,0 +1,39 @@ +#!/bin/python3 + +import math +import os +import random +import re +import sys + +# +# Complete the 'rotateLeft' function below. +# +# The function is expected to return an INTEGER_ARRAY. +# The function accepts following parameters: +# 1. INTEGER d +# 2. INTEGER_ARRAY arr +# + +def rotateLeft(d, arr): + # Write your code here + arr = arr[d:]+arr[0:d] + return arr + +if __name__ == '__main__': + fptr = open(os.environ['OUTPUT_PATH'], 'w') + + first_multiple_input = input().rstrip().split() + + n = int(first_multiple_input[0]) + + d = int(first_multiple_input[1]) + + arr = list(map(int, input().rstrip().split())) + + result = rotateLeft(d, arr) + + fptr.write(' '.join(map(str, result))) + fptr.write('\n') + + fptr.close() From 728fdd65c138f750207f8230aa293748c38ceeac Mon Sep 17 00:00:00 2001 From: manishkheta321 Date: Thu, 8 Oct 2020 21:55:41 +0530 Subject: [PATCH 35/36] added solution --- Stone/Manish/solution.cpp | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Stone/Manish/solution.cpp diff --git a/Stone/Manish/solution.cpp b/Stone/Manish/solution.cpp new file mode 100644 index 0000000..30c5ddd --- /dev/null +++ b/Stone/Manish/solution.cpp @@ -0,0 +1,86 @@ +#include + +#define pb push_back +#define mp make_pair +#define fr first +#define sc second +#define clr(a) memset(a, 0, sizeof(a)) +#define sz(x) x.size() +#define rep(n) for (ll i = 0; i < n; i++) +#define repc(i, n) for (ll i = 0; i < n; i++) +#define FOR(i, x, y) for (int i = x; i < y; i++) +#define DEC(i, x, y) for (int i = x; i >= y; i--) +#define all(v) v.begin(), v.end() +#define min3(a, b, c) min(a, min(b, c)) +#define max3(a, b, c) max(a, max(b, c)) +#define alla(a, n) a, a + n +#define debug1(x) cout< ii; +typedef vector vi; +typedef vector vii; + + +template +T modpow(T base, T exp, T modulus){ + base %= modulus; T result = 1; + while(exp > 0){ + if(exp & 1) result = (result * base) % modulus; + base = (base * base) % modulus; + exp >>= 1; + } + return result; +} +ll lcm(ll a, ll b) { return (a * (b / __gcd(a, b))); } + +// Some contants +const int inf = 1e9 + 7; +const double eps = 1e-6; +const double pi = 1.00 * acos(-1.00); + + + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + ll t=1; + cin>>t; + while(t--) + { + ll a,b,c; + cin>>a>>b>>c; + ll ans=0; + + //debug3(a,b,c); + if(b==0) + { + cout<<0< Date: Fri, 9 Oct 2020 11:30:49 +0530 Subject: [PATCH 36/36] Added code in python --- Chef and Recipe/Ayush/chefAndRecipe.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Chef and Recipe/Ayush/chefAndRecipe.py diff --git a/Chef and Recipe/Ayush/chefAndRecipe.py b/Chef and Recipe/Ayush/chefAndRecipe.py new file mode 100644 index 0000000..b426522 --- /dev/null +++ b/Chef and Recipe/Ayush/chefAndRecipe.py @@ -0,0 +1,28 @@ +t=int(input()) +for k in range(t): + n=int(input()) + l=list(map(int,input().split()))[:n] + i=0 + c=0 + done=[] + done1=[] + while(i