From 188ced7d69ba65689475b1794fa1b48df2985470 Mon Sep 17 00:00:00 2001 From: Ayushjain1722 Date: Fri, 5 Oct 2018 20:58:03 +0530 Subject: [PATCH 01/47] Git Rocks --- PATTERN2.CPP | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 PATTERN2.CPP diff --git a/PATTERN2.CPP b/PATTERN2.CPP new file mode 100644 index 0000000..18a269d --- /dev/null +++ b/PATTERN2.CPP @@ -0,0 +1,81 @@ +#include +#include +void main() +{ + clrscr(); + int n,i,j,k; + cout<<"Enter Value Of n: "; + cin>>n; + int space=n-1; + for(i=1; i<=n;i++) + { + cout<=1;k--) + { + cout<<" "; + } + space--; + for(j=1; j<=i; j++) + cout<=1; j--) + cout<>n; + space=n-1; + for(i=1; i<=n;i++) + { + cout<=1;k--) + cout<<" "; + for (j=1; j<=(2*i)-1; j++) + cout<<'*'; + space--; + } + space=1; + for (i=1; i<=n-1; i++) + { + cout<=1; k--) + cout<<" "; + for(j=1;j<=2*(n-i)-1;j++) + cout<<'*'; + space++; + } + getch(); +} + +/* +Enter Value Of n: 5 + + + 1 + 121 + 12321 + 1234321 +123454321 + +Enter Value Of n: 6 + + * + *** + ***** + ******* + ********* +*********** + ********* + ******* + ***** + *** + * + +*/ + + + + + + From 3e3fa50443927e8f5a358b1aa9213b47e69b49c4 Mon Sep 17 00:00:00 2001 From: Ayushjain1722 Date: Tue, 9 Oct 2018 11:51:14 +0530 Subject: [PATCH 02/47] Git Rocks --- AAL/Aditya And Ladders.txt | 31 +++++++++++++++++++++++++++++++ AAL/x.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 AAL/Aditya And Ladders.txt create mode 100644 AAL/x.cpp diff --git a/AAL/Aditya And Ladders.txt b/AAL/Aditya And Ladders.txt new file mode 100644 index 0000000..273d877 --- /dev/null +++ b/AAL/Aditya And Ladders.txt @@ -0,0 +1,31 @@ +Aditya is fond of ladders. Everyday he goes through pictures of ladders online but unfortunately today he ran out of ladder pictures online. Write a program to print “ladder with N steps”, which he can use to get his daily dose of ladder love. + +INPUT: +Input contains integer N, the number of steps in the ladder + +OUTPUT: + +Print the ladder with the gap between two side rails being 3 spaces(“ “). + +Check the sample output for format of printing the ladder. + +CONSTRAINTS: + +1<=N<=40 + +Sample Input : 4 +Sample Output: +* * +* * +***** +* * +* * +***** +* * +* * +***** +* * +* * +***** +* * +* * \ No newline at end of file diff --git a/AAL/x.cpp b/AAL/x.cpp new file mode 100644 index 0000000..65b0a5b --- /dev/null +++ b/AAL/x.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main() + +{ + +int N,i=0; + +cin>>N; + +while(i Date: Thu, 10 Oct 2019 11:47:52 +0530 Subject: [PATCH 03/47] Added Bytelandian Gold coins --- Bytelandian-gold-coins/instructions.txt | 27 +++++++++++++++++++++++++ Bytelandian-gold-coins/solution.cpp | 17 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Bytelandian-gold-coins/instructions.txt create mode 100644 Bytelandian-gold-coins/solution.cpp diff --git a/Bytelandian-gold-coins/instructions.txt b/Bytelandian-gold-coins/instructions.txt new file mode 100644 index 0000000..74c2c86 --- /dev/null +++ b/Bytelandian-gold-coins/instructions.txt @@ -0,0 +1,27 @@ +In Byteland they have a very strange monetary system. + +Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit). + +You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. + +You have one gold coin. What is the maximum amount of American dollars you can get for it? +Input + +The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin. +Output + +For each test case output a single line, containing the maximum amount of American dollars you can make. + +Example + +Input: +12 +2 + +Output: +13 +2 + +You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. +If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. +It is better just to change the 2 coin directly into $2. diff --git a/Bytelandian-gold-coins/solution.cpp b/Bytelandian-gold-coins/solution.cpp new file mode 100644 index 0000000..aebf1b2 --- /dev/null +++ b/Bytelandian-gold-coins/solution.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +map dp; +long long optcoins(int n){ + if(n<12) + return n; + if(dp.count(n)) + return dp[n]; + dp[n]=optcoins(n/2)+optcoins(n/3)+optcoins(n/4); + return dp[n]; +} +int main(){ + int x; + while(scanf("%d",&x)!=EOF) + printf("%lld\n",optcoins(x)); + return 0; +} From 5262e5a04be85a342de0cd3a922b844d460593f6 Mon Sep 17 00:00:00 2001 From: hrishit biswas Date: Thu, 10 Oct 2019 11:53:31 +0530 Subject: [PATCH 04/47] Added Philosophers Stone --- Philosophers_Stone/question.txt | 30 ++++++++++++++++++++++++++++++ Philosophers_Stone/solution.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Philosophers_Stone/question.txt create mode 100644 Philosophers_Stone/solution.cpp diff --git a/Philosophers_Stone/question.txt b/Philosophers_Stone/question.txt new file mode 100644 index 0000000..f2474d3 --- /dev/null +++ b/Philosophers_Stone/question.txt @@ -0,0 +1,30 @@ + + +One of the secret chambers in Hogwarts is full of philosopher’s stones. The floor of the chamber is covered by h Ă— w square tiles, where there are h rows of tiles from front (first row) to back (last row) and w columns of tiles from left to right. Each tile has 1 to 100 stones on it. Harry has to grab as many philosopher’s stones as possible, subject to the following restrictions: + + He starts by choosing any tile in the first row, and collects the philosopher’s stones on that tile. Then, he moves to a tile in the next row, collects the philosopher’s stones on the tile, and so on until he reaches the last row. + When he moves from one tile to a tile in the next row, he can only move to the tile just below it or diagonally to the left or right. + +Given the values of h and w, and the number of philosopher’s stones on each tile, write a program to compute the maximum possible number of philosopher’s stones Harry can grab in one single trip from the first row to the last row. +Input + +The first line consists of a single integer T, the number of test cases. In each of the test cases, the first line has two integers. The first integer h (1 <= h <= 100) is the number of rows of tiles on the floor. The second integer w (1 <= w <= 100) is the number of columns of tiles on the floor. Next, there are h lines of inputs. The i-th line of these, specifies the number of philosopher’s stones in each tile of the i-th row from the front. Each line has w integers, where each integer m (0 <= m <= 100) is the number of philosopher’s stones on that tile. The integers are separated by a space character. +Output + +The output should consist of T lines, (1 <= T <= 100), one for each test case. Each line consists of a single integer, which is the maximum possible number of philosopher’s stones Harry can grab, in one single trip from the first row to the last row for the corresponding test case. +Example + +Input: +1 +6 5 +3 1 7 4 2 +2 1 3 1 1 +1 2 2 1 8 +2 2 1 5 3 +2 1 4 4 4 +5 2 7 5 1 + +Output: +32 + +//7+1+8+5+4+7=32 diff --git a/Philosophers_Stone/solution.cpp b/Philosophers_Stone/solution.cpp new file mode 100644 index 0000000..f3cc8e7 --- /dev/null +++ b/Philosophers_Stone/solution.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main(void) +{ + int t; + cin>>t; + while(t--) + { + int r,c; + cin>>r>>c; + int arr[r][c+2]={0}; + arr[0][c+1]=0; + + for(int i=0;i>arr[i][j]; + + for(int i=r-2;i>=0;i--) + for(int j=1;j<=c;j++) + arr[i][j]+=max((arr[i+1][j-1]),max(arr[i+1][j],arr[i+1][j+1])); + + int max = INT_MIN; + for(int i=1;i<=c;i++) + if(arr[0][i]>max) + max = arr[0][i]; + + cout< Date: Thu, 10 Oct 2019 09:51:55 +0200 Subject: [PATCH 05/47] added bubble_sort_c --- bubble_sort_c/question.txt | 2 ++ bubble_sort_c/solution/bubble_sort.c | 23 +++++++++++++++++++++++ bubble_sort_c/solution/bubble_sort.h | 5 +++++ bubble_sort_c/solution/main.c | 12 ++++++++++++ bubble_sort_c/solution/print_array.c | 10 ++++++++++ 5 files changed, 52 insertions(+) create mode 100644 bubble_sort_c/question.txt create mode 100644 bubble_sort_c/solution/bubble_sort.c create mode 100644 bubble_sort_c/solution/bubble_sort.h create mode 100644 bubble_sort_c/solution/main.c create mode 100644 bubble_sort_c/solution/print_array.c diff --git a/bubble_sort_c/question.txt b/bubble_sort_c/question.txt new file mode 100644 index 0000000..bd6c83d --- /dev/null +++ b/bubble_sort_c/question.txt @@ -0,0 +1,2 @@ +Make a C program to bubble sort this array of integers (smallest to biggest): {303, -909, 101, 42, 0, 42, 21, 1, 2} +Expected result => {-909, 0, 1, 2, 21. 42, 42, 101, 303} diff --git a/bubble_sort_c/solution/bubble_sort.c b/bubble_sort_c/solution/bubble_sort.c new file mode 100644 index 0000000..8f7ab02 --- /dev/null +++ b/bubble_sort_c/solution/bubble_sort.c @@ -0,0 +1,23 @@ +#include "bubble_sort.h" + +void swap_values(int *a, int *b) +{ + int buffer = *a; + *a = *b; + *b = buffer; +} + +int *bubble_sort(int *arr, size_t arr_len) +{ + size_t i = 0; + + while (i++ < arr_len) + { + if (arr[i] < arr[i-1]) + { + swap_values(&arr[i], &arr[i-1]); + i = 0; + } + } + return(arr); +} diff --git a/bubble_sort_c/solution/bubble_sort.h b/bubble_sort_c/solution/bubble_sort.h new file mode 100644 index 0000000..4e69c28 --- /dev/null +++ b/bubble_sort_c/solution/bubble_sort.h @@ -0,0 +1,5 @@ +#include +#include + +int *bubble_sort(int *arr, size_t arr_len); +void print_array(int *arr, size_t arr_len); diff --git a/bubble_sort_c/solution/main.c b/bubble_sort_c/solution/main.c new file mode 100644 index 0000000..9616442 --- /dev/null +++ b/bubble_sort_c/solution/main.c @@ -0,0 +1,12 @@ +#include "bubble_sort.h" + +int main(void) +{ + int to_sort[] = {303, -909, 101, 42, 0, 42, 21, 1, 2}; + size_t arr_len = sizeof(to_sort) / sizeof(to_sort[0]); + int *sorted = bubble_sort(to_sort, arr_len); + + print_array(sorted, arr_len); + + return(EXIT_SUCCESS); +} diff --git a/bubble_sort_c/solution/print_array.c b/bubble_sort_c/solution/print_array.c new file mode 100644 index 0000000..39c130a --- /dev/null +++ b/bubble_sort_c/solution/print_array.c @@ -0,0 +1,10 @@ +#include "bubble_sort.h" + +void print_array(int *arr, size_t arr_len) +{ + size_t i; + + printf("Sorted array:\n"); + for (i = 0; i < arr_len; i++) + printf("%d\n", arr[i]); +} From 4e500b08e2eb4c0564a967657c6543061ebd8909 Mon Sep 17 00:00:00 2001 From: saksham Date: Thu, 10 Oct 2019 19:42:29 +0530 Subject: [PATCH 06/47] Added question-name --- .../insertion_sort.cpp | 182 ++++++++++++++++++ Insertion_sort_using_classes/problem.txt | 7 + 2 files changed, 189 insertions(+) create mode 100644 Insertion_sort_using_classes/insertion_sort.cpp create mode 100644 Insertion_sort_using_classes/problem.txt diff --git a/Insertion_sort_using_classes/insertion_sort.cpp b/Insertion_sort_using_classes/insertion_sort.cpp new file mode 100644 index 0000000..8aaa360 --- /dev/null +++ b/Insertion_sort_using_classes/insertion_sort.cpp @@ -0,0 +1,182 @@ +#include +using namespace std; + +/* Hi I am using my own class to use in insertion sort function*/ + +template +class LinearList{ + private: + int MaxSize; + Item *element; // 1D dynamic array + int len; + public: + /* Default constructor. + * Should create an empty list that not contain any elements*/ + LinearList() + { + element=nullptr; + len=0; + }; + + /* This constructor should create a list containing MaxSize elements. You can intialize the elements with any values.*/ + LinearList(const int& MaxListSize) + { + MaxSize=MaxListSize; + element = new Item[MaxSize]; + len=0; + + }; + + /* Destructor. + * Must free all the memory contained by the list */ + ~LinearList(){}; + + /* Indexing operator. + * It should behave the same way array indexing does. i.e, + * LinearList L; + * L[0] should refer to the first element; + * L[1] to the second element and so on. + * */ + Item& operator[](const int& i) + { + return element[i]; + }; //return i'th element of list + + /* Returns true if the list is empty, false otherwise. + * */ + bool isEmpty() + { + if(len==0) + { + return true; + } + else + { + return false; + } + }; + + /* Returns the actual length (number of elements) in the list. + * */ + int length() + { + return len; + }; + + /* Returns the maximum size of the list. + * */ + int maxSize() + { + return maxSize; + }; + + /* Returns the k-th element of the list. + * */ + Item returnListElement(const int k) + { + return element[k-1]; + }; + /* Set x to the k-th element and + * return true if k-th element is present otherwise return false. + * */ + bool find(const int k, Item& x) + { + if(x==element[k-1]) + { + return true; + } + else + { + + return false; + } + }; + + /* Search for x and + * return the position if found, else return 0. + * */ + int search(Item& x) + { + for(int i=0;ik;i--) + { + element[i]=element[i-1]; + } + element[k]=x; + len=len+1; + }; + + +}; + +//insertion sort function +void insertionSort(LinearList& A) + { + int i,j,temp,len; + i=j=0; + len=A.length(); + j=len; + for(i=1;i-1;j--) + { + if(temp> n; + LinearList l(100); + + for(i=0;i> temp; + l.insert(i,temp); + } + insertionSort(l); + for(i=0;i Date: Fri, 11 Oct 2019 15:08:48 +0530 Subject: [PATCH 07/47] Mislove Has Lost an Array Added a new problem with the solution --- Question.txt | Bin 0 -> 1692 bytes Solution.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Question.txt create mode 100644 Solution.cpp diff --git a/Question.txt b/Question.txt new file mode 100644 index 0000000000000000000000000000000000000000..6abcaf90baa35bd5d28c5f804e8e59cd5f2d315b GIT binary patch literal 1692 zcmb7^&2H0B5QS%r#5-7QDx?B((m(~uf(?QNV#5w~;j~U0;l#xb&^|S90Gw|oBRkND zqUgr=-kCXb=I73@pYLsDy*1X_H><6%E3526-^w=r-&v>qt?x@a_V2{MKOV&iz1Eic zXLqfAFU+l0Ag*-3751f8CmB`?`>H#yV|26 z)wF|V+2|l&gk_eM$+EKsIsk9qsB@my9;ovC&hT|2%wz! zI@5hb9a1!MP3+8GNuE7R&c?VKJMx=D=%=#Bx)zs8TzY2#=giwaTPj5EH(t3D+5Wr# z;P*egriyQRCol3DyjuCqNsyhHvDWrQkyOen*>Ckni$>u&?hV9`F z8|wBaR>tyo--1Zr&h2#f%IMJ7svq6dc|BsjMC^eabsZ)Sy&ID$>)hLCuPc-3*84KE z7hM`}GtdgX0eWDiZ{#_1JIE`$8OdYvGJ6;Pb_(?mGm2Rg^BEi}wm%J!$MlNHGQ1up taL&kg;&Ls#tvyk#xur9C+Y>*1a9L;|ok{Y-C1cCbMaG<&9kiTE{u|k>5~lzF literal 0 HcmV?d00001 diff --git a/Solution.cpp b/Solution.cpp new file mode 100644 index 0000000..4cf529c --- /dev/null +++ b/Solution.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; + cin>>n>>s>>e; + + for(i=1;i<=s-1;i++) + { + mini=2*mini; + mine+=mini; + } +mine+=n-s+1; + +for(i=1;i<=e-1;i++) +{ + maxi=2*maxi; + maxo+=maxi; +} +maxo+=1; + + +maxo+=(n-e)*(maxi); +cout< Date: Fri, 11 Oct 2019 15:14:32 +0530 Subject: [PATCH 08/47] Create Question.txt --- Mislove Has Lost an Array/Question.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Mislove Has Lost an Array/Question.txt diff --git a/Mislove Has Lost an Array/Question.txt b/Mislove Has Lost an Array/Question.txt new file mode 100644 index 0000000..23182ac --- /dev/null +++ b/Mislove Has Lost an Array/Question.txt @@ -0,0 +1,17 @@ +Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it: + +1)The number of different numbers in the array is not less than l and is not greater than r. +2)For each array's element ai either ai=1 or ai is even and there is a number ai/2 in the array. + +For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2=8. + +According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array. + +Input-1 +4 2 2 +Output +5 7 +Input-2 +5 1 5 +Output +5 31 From 12e12e485d14e4d5fc800fbe89ae0904b98131a5 Mon Sep 17 00:00:00 2001 From: Aditya Jain <31203114+Adityajain732@users.noreply.github.com> Date: Fri, 11 Oct 2019 15:15:20 +0530 Subject: [PATCH 09/47] Create Solution.cpp --- Mislove Has Lost an Array/Solution.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Mislove Has Lost an Array/Solution.cpp diff --git a/Mislove Has Lost an Array/Solution.cpp b/Mislove Has Lost an Array/Solution.cpp new file mode 100644 index 0000000..841440f --- /dev/null +++ b/Mislove Has Lost an Array/Solution.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; + cin>>n>>s>>e; + + for(i=1;i<=s-1;i++) + { + mini=2*mini; + mine+=mini; + } +mine+=n-s+1; + +for(i=1;i<=e-1;i++) +{ + maxi=2*maxi; + maxo+=maxi; +} +maxo+=1; + + +maxo+=(n-e)*(maxi); +cout< Date: Fri, 11 Oct 2019 15:17:17 +0530 Subject: [PATCH 10/47] Delete Question.txt --- Question.txt | Bin 1692 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Question.txt diff --git a/Question.txt b/Question.txt deleted file mode 100644 index 6abcaf90baa35bd5d28c5f804e8e59cd5f2d315b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1692 zcmb7^&2H0B5QS%r#5-7QDx?B((m(~uf(?QNV#5w~;j~U0;l#xb&^|S90Gw|oBRkND zqUgr=-kCXb=I73@pYLsDy*1X_H><6%E3526-^w=r-&v>qt?x@a_V2{MKOV&iz1Eic zXLqfAFU+l0Ag*-3751f8CmB`?`>H#yV|26 z)wF|V+2|l&gk_eM$+EKsIsk9qsB@my9;ovC&hT|2%wz! zI@5hb9a1!MP3+8GNuE7R&c?VKJMx=D=%=#Bx)zs8TzY2#=giwaTPj5EH(t3D+5Wr# z;P*egriyQRCol3DyjuCqNsyhHvDWrQkyOen*>Ckni$>u&?hV9`F z8|wBaR>tyo--1Zr&h2#f%IMJ7svq6dc|BsjMC^eabsZ)Sy&ID$>)hLCuPc-3*84KE z7hM`}GtdgX0eWDiZ{#_1JIE`$8OdYvGJ6;Pb_(?mGm2Rg^BEi}wm%J!$MlNHGQ1up taL&kg;&Ls#tvyk#xur9C+Y>*1a9L;|ok{Y-C1cCbMaG<&9kiTE{u|k>5~lzF From 98ede3e688977704efafc42e2afcf5e1fea41dda Mon Sep 17 00:00:00 2001 From: Aditya Jain <31203114+Adityajain732@users.noreply.github.com> Date: Fri, 11 Oct 2019 15:17:43 +0530 Subject: [PATCH 11/47] Delete Solution.cpp --- Solution.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Solution.cpp diff --git a/Solution.cpp b/Solution.cpp deleted file mode 100644 index 4cf529c..0000000 --- a/Solution.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; - cin>>n>>s>>e; - - for(i=1;i<=s-1;i++) - { - mini=2*mini; - mine+=mini; - } -mine+=n-s+1; - -for(i=1;i<=e-1;i++) -{ - maxi=2*maxi; - maxo+=maxi; -} -maxo+=1; - - -maxo+=(n-e)*(maxi); -cout< Date: Sat, 12 Oct 2019 00:24:54 +0530 Subject: [PATCH 12/47] add sudoku code --- SudokuSolver/Question.txt | 20 +++++++ SudokuSolver/sudokuSolver.cpp | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 SudokuSolver/Question.txt create mode 100755 SudokuSolver/sudokuSolver.cpp diff --git a/SudokuSolver/Question.txt b/SudokuSolver/Question.txt new file mode 100644 index 0000000..eadd651 --- /dev/null +++ b/SudokuSolver/Question.txt @@ -0,0 +1,20 @@ +Given a partially filled NxN 2D array, the goal is to assign digits (from 1 to 9) +to the empty cells (cells assigned O value) so that every row, column,and subgrid +of size 3Ă—3 contains exactly one instance of the digits from 1 to 9. We provide the +value of N and a partially filled sudoku as input. + +Sample Input: +4 +3 4 1 0 0 2 0 0 0 0 2 0 0 1 4 3 + +Sample Output: +============== +3 4 1 0 +0 2 0 0 +0 0 2 0 +0 1 4 3 +============== +3 4 1 2 +1 2 3 4 +4 3 2 1 +2 1 4 3 diff --git a/SudokuSolver/sudokuSolver.cpp b/SudokuSolver/sudokuSolver.cpp new file mode 100755 index 0000000..e088400 --- /dev/null +++ b/SudokuSolver/sudokuSolver.cpp @@ -0,0 +1,100 @@ +#include +#include +using namespace std; + +void print2D(int arr[][20], int M, int N) { + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + cout << arr[i][j] << " "; + } + cout << endl; + } +} + +bool myfixed[20][20] = {}; + +void input2D_soduku(int arr[][20], int M, int N) +{ + for (int i = 0; i < M; ++i) + { + for (int j = 0; j < N; ++j) + { + cin >> arr[i][j]; + if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change + } + } +} + +bool canPlace(int board[][20], int N, int x, int y, int num) +{ + //check along row && col + for (int i = 0; i < N; ++i) + { + if (board[x][i] == num) return false; //check along row + if (board[i][y] == num) return false; //check along col + } + + //check in the box + int rootN = sqrt(N); + int boxRow = x / rootN; + int boxCol = y / rootN; + int startRow = boxRow * rootN; + int startCol = boxCol * rootN; + + for (int r = startRow; r < startRow + rootN; ++r) + { + for (int c = startCol; c < startCol + rootN; ++c) + { + if (board[r][c] == num) return false; + } + } + + return true; +} + + +bool solveSudoku(int board[][20], int N, int x, int y) +{ + if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over + + if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row + + if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); + + for (int num = 1; num <= N; ++num) + { + if (canPlace(board, N, x, y, num) == true) + { + board[x][y] = num; + bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns + if (isSuccessful) return true; + else board[x][y] = 0; + } + } + return false; +} + +int main() +{ + int board[20][20] = {}; + + int N; + cin >> N; + input2D_soduku(board, N, N); + for(int i=0;i>board[i][j]; + } + } + cout << "==============\n"; + + print2D(board, N, N); + + cout << "==============\n"; + + solveSudoku(board, N, 0, 0); + + print2D(board, N, N); + +} + From e476f2bc45b933621a6664394486b13575547f79 Mon Sep 17 00:00:00 2001 From: Muskan Goyal Date: Sat, 12 Oct 2019 00:30:31 +0530 Subject: [PATCH 13/47] fixed --- .DS_Store | Bin 12292 -> 12292 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index fa501d182026124fbe10cdd77cce43730721611a..6b19b25ca24f98b36d6bffae549b9dbe6dc5f790 100644 GIT binary patch delta 29 hcmZokXi3-ULYy6d4gn#7y$9!55fQd From b45f9080f318bb6832aaa2dac64293e38bf05758 Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 01:39:18 +0530 Subject: [PATCH 14/47] Added POLYMUL from SPOJ --- PolyMul/question.txt | 31 ++++++++++++++++ PolyMul/solution.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 PolyMul/question.txt create mode 100644 PolyMul/solution.cpp diff --git a/PolyMul/question.txt b/PolyMul/question.txt new file mode 100644 index 0000000..2d08f19 --- /dev/null +++ b/PolyMul/question.txt @@ -0,0 +1,31 @@ +Sam and Dean fight the supernatural creatures to protect the humans. Now they have come across a creature called the Vedala, which are always found in pairs. Each vedala can be represented by a polynomial. Both the Vedalas need to be killed at once or else they can't be killed. They can be killed only by using the product of the two polynomials representing the two Vedala. Help Sam and Dean find the product of the polynomials fast, so they can do thier work. + +Input + +First line contains an integer T (≤ 10), number of test cases. +Each test case will have n (n ≤ 10000), maximum degree of the polynomials on the first line. + +Next two lines will have n+1 space separated integers each representing the coeffiecients of first and second polynomials respectively. + +All input coefficients values are <=1000. + +Output +For each test case ouput a line of 2n space seperated integers indicating coefficients of the polynomial created after multiplication. + + +Example +Input: +2 +2 +1 2 3 +3 2 1 +2 +1 0 1 +2 1 0 + +Output: +3 8 14 8 3 +2 1 2 1 0 + + + diff --git a/PolyMul/solution.cpp b/PolyMul/solution.cpp new file mode 100644 index 0000000..f439663 --- /dev/null +++ b/PolyMul/solution.cpp @@ -0,0 +1,86 @@ +#include + +using namespace std; + +typedef long long int LL; +typedef vector VLL; +typedef std::complex CD; + +#define PB push_back +#define F first +#define s second +#define SZ(x) x.size() +#define ALL(a) std::begin(a), std::end(a) +#define IN_REP int _t; cin >> _t ; while(_t--) +#define IOS ios::sync_with_stdio(false);cin.tie(NULL) +#define FOR(i, a, b) for(int i=(a);i<(b);i++) +#define REP(i, n) FOR(i,0,n) +const double PI = acos(-1); +typedef std::valarray CArray; + +// Cooley–Tukey FFT (in-place) +void fft(CArray &x) { + // const size_t N = x.size(); + int N = SZ(x); + if (N <= 1) return; + + // divide + CArray even = x[std::slice(0, N / 2, 2)]; + CArray odd = x[std::slice(1, N / 2, 2)]; + + // conquer + fft(even); + fft(odd); + + // combine + // for (size_t k = 0; k < N/2; ++k){ + for (int k = 0; k < N / 2; ++k) { + CD t = std::polar(1.0, -2 * PI * k / N) * odd[k]; + x[k] = even[k] + t; + x[k + N / 2] = even[k] - t; + } +} + +// inverse fft (in-place) +void ifft(CArray &x) { + // conjugate the complex numbers + x = x.apply(std::conj); + + // forward fft + fft(x); + + // conjugate the complex numbers again + x = x.apply(std::conj); + + // scale the numbers + x /= x.size(); +} + +int main() { + IOS; + IN_REP { + int n; + cin >> n; + n++; // Given in question + int size = 2 * (1 << int(ceil(log2(n)))); + + CArray x(size), y(size); + FOR(i, size - n, size) cin >> x[i]; + fft(x); + FOR(i, size - n, size) cin >> y[i]; + fft(y); + + CArray res(size); + res = x * y; + ifft(res); + VLL ans; + REP(i, size - 1) { + ans.PB(round(res[i].real())); + } + for (int i = size - 1 - (2 * n - 1); i < size - 1; i++) { + cout << ans[i] << " "; + } + cout << endl; + } + return 0; +} From 270e0ab39788d6bb9007e7d3f235f2cc22494410 Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 02:15:22 +0530 Subject: [PATCH 15/47] Added Strange Food Chain --- Strange_Food_Chain/question.txt | 37 ++++++++++++++++++++++++ Strange_Food_Chain/solution.cpp | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Strange_Food_Chain/question.txt create mode 100644 Strange_Food_Chain/solution.cpp diff --git a/Strange_Food_Chain/question.txt b/Strange_Food_Chain/question.txt new file mode 100644 index 0000000..ae9b410 --- /dev/null +++ b/Strange_Food_Chain/question.txt @@ -0,0 +1,37 @@ +There are 3 kinds of animals A,B and C. A can eat B,B can eat C,C can eat A. It's interesting,isn't it? + +Now we have n animals,numbered from 1 to n. Each of them is one of the 3 kinds of animals:A,B,C. + +Today Mary tells us k pieces of information about these n animals. Each piece has one of the two forms below: + +1 x y: It tells us the kind of x and y are the same. +2 x y: It tells us x can eat y. +Some of these k pieces are true,some are false. The piece is false if it satisfies one of the 3 conditions below, otherwise it's true. + +X or Y in this piece is larger than n. +This piece tells us X can eat X. +This piece conflicts to some true piece before. +Input +The first line contains a single integer t.t blocks follow. + +To every block,the first line contains two integers n(1<=n<=50000) and k (1<=k<=100000). k lines follow,each contains 3 positive integers D(1<=D<=2),X,Y,separated by single spaces. + + +Output +t lines,each contains a single integer - the number of false pieces in the corresponding block. + + +Example +Sample input: +1 +100 7 +1 101 1 +2 1 2 +2 2 3 +2 3 3 +1 1 3 +2 3 1 +1 5 5 + +Sample output: +3 diff --git a/Strange_Food_Chain/solution.cpp b/Strange_Food_Chain/solution.cpp new file mode 100644 index 0000000..ba8dc5b --- /dev/null +++ b/Strange_Food_Chain/solution.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +const int N = 5e4 + 10; + +int n, k; +int par[N], lab[N]; + +int anc(int u) { + if (u == par[u]) return u; + int tmp = par[u]; + par[u] = anc(par[u]); + lab[u] = lab[tmp] + lab[u]; + return par[u]; +} + +int main() { + // freopen("input.in", "r", stdin); +// freopen("output.out", "w", stdout); + + int test; scanf("%d", &test); + while (test--) { + scanf("%d%d", &n, &k); + for (int i = 1; i <= n; ++i) { + par[i] = i; + lab[i] = 0; + } + int answer = 0; + while (k--) { + int t, x, y; scanf("%d%d%d", &t, &x, &y); + if (x > n || y > n) { answer++; continue; } + int px = anc(x), py = anc(y); + t--; + if (px == py) { + int tmp = (lab[x] - lab[y]) % 3; if (tmp < 0) tmp += 3; + if (tmp != t) answer++; + } else { + par[px] = py; + int i = (lab[x] - lab[y] - t) % 3; + lab[px] = i < 0 ? -i : -i + 3; + } + } + printf("%d\n", answer); + } + + return 0; +} + + From f37b68bb189374f3fad46460880b617c1c140e7e Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 02:18:22 +0530 Subject: [PATCH 16/47] Added Chocolate Spoj Problem --- Chocolate_SPOJ/question.txt | 41 ++++++++ Chocolate_SPOJ/solution.java | 182 +++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 Chocolate_SPOJ/question.txt create mode 100644 Chocolate_SPOJ/solution.java diff --git a/Chocolate_SPOJ/question.txt b/Chocolate_SPOJ/question.txt new file mode 100644 index 0000000..8f45eef --- /dev/null +++ b/Chocolate_SPOJ/question.txt @@ -0,0 +1,41 @@ +We are given a bar of chocolate composed of m*n square pieces. One should break the chocolate into single squares. Parts of the chocolate may be broken along the vertical and horizontal lines as indicated by the broken lines in the picture. + +A single break of a part of the chocolate along a chosen vertical or horizontal line divides that part into two smaller ones. Each break of a part of the chocolate is charged a cost expressed by a positive integer. This cost does not depend on the size of the part that is being broken but only depends on the line the break goes along. Let us denote the costs of breaking along consecutive vertical lines with x1, x2, ..., xm-1 and along horizontal lines with y1, y2, ..., yn-1. + +The cost of breaking the whole bar into single squares is the sum of the successive breaks. One should compute the minimal cost of breaking the whole chocolate into single squares. + + +For example, if we break the chocolate presented in the picture first along the horizontal lines, and next each obtained part along vertical lines then the cost of that breaking will be y1+y2+y3+4*(x1+x2+x3+x4+x5). + +Task +Write a program that for each test case: + +Reads the numbers x1, x2, ..., xm-1 and y1, y2, ..., yn-1 +Computes the minimal cost of breaking the whole chocolate into single squares, writes the result. +Input +One integer in the first line, stating the number of test cases, followed by a blank line. There will be not more than 20 tests. + +For each test case, at the first line there are two positive integers m and n separated by a single space, 2 <= m,n <= 1000. In the successive m-1 lines there are numbers x1, x2, ..., xm-1, one per line, 1 <= xi <= 1000. In the successive n-1 lines there are numbers y1, y2, ..., yn-1, one per line, 1 <= yi <= 1000. + +The test cases will be separated by a single blank line. + +Output +For each test case : write one integer - the minimal cost of breaking the whole chocolate into single squares. + + +Example +Input: +1 + +6 4 +2 +1 +3 +1 +4 +4 +1 +2 + +Output: +42 diff --git a/Chocolate_SPOJ/solution.java b/Chocolate_SPOJ/solution.java new file mode 100644 index 0000000..f04b8c2 --- /dev/null +++ b/Chocolate_SPOJ/solution.java @@ -0,0 +1,182 @@ +import java.io.OutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.io.BufferedWriter; +import java.io.Writer; +import java.io.OutputStreamWriter; +import java.util.InputMismatchException; +import java.io.IOException; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * + * @author Rishabhdeep Singh + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream = System.in; + OutputStream outputStream = System.out; + InputReader in = new InputReader(inputStream); + OutputWriter out = new OutputWriter(outputStream); + MultipleTestcases solver = new MultipleTestcases(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } + + static class MultipleTestcases { + public void solve(int testNumber, InputReader in, OutputWriter out) { + int n = in.nextInt(); + int m = in.nextInt(); + --n; + --m; + int[] x = in.nextIntArray(n); + int[] y = in.nextIntArray(m); + int s1 = 0, s2 = 0; + for (int i = 0; i < n; i++) { + s1 += x[i]; + } + for (int i = 0; i < m; i++) { + s2 += y[i]; + } + Arrays.sort(x); + Arrays.sort(y); + int ans = s1 + s2; + for (int i = n - 1, j = m - 1; i >= 0 && j >= 0; ) { + if (y[j] >= x[i]) { + ans += s1; + s2 -= y[j]; + --j; + } else { + ans += s2; + s1 -= x[i]; + --i; + } + } + out.println(ans); + } + + } + + static class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void close() { + writer.close(); + } + + public void println(int i) { + writer.println(i); + } + + } + + static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + private InputReader.SpaceCharFilter filter; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) { + throw new InputMismatchException(); + } + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) { + return -1; + } + } + return buf[curChar++]; + } + + public int nextInt() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') { + throw new InputMismatchException(); + } + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String nextString() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + StringBuilder res = new StringBuilder(); + do { + if (Character.isValidCodePoint(c)) { + res.appendCodePoint(c); + } + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + public boolean isSpaceChar(int c) { + if (filter != null) { + return filter.isSpaceChar(c); + } + return isWhitespace(c); + } + + public static boolean isWhitespace(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + public String next() { + return nextString(); + } + + public int[] nextIntArray(int n) { + int[] array = new int[n]; + for (int i = 0; i < n; ++i) array[i] = nextInt(); + return array; + } + + public interface SpaceCharFilter { + public boolean isSpaceChar(int ch); + + } + + } +} + From 2cc9056c974acf2041f1f93da64b1a7020837211 Mon Sep 17 00:00:00 2001 From: ShivamMangale Date: Tue, 15 Oct 2019 04:43:31 +0530 Subject: [PATCH 17/47] Added White-Sheet --- White-Sheet/White-Sheet.txt | 54 +++++++++++++++++++++++++++++++++++ White-Sheet/code.cpp | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 White-Sheet/White-Sheet.txt create mode 100644 White-Sheet/code.cpp diff --git a/White-Sheet/White-Sheet.txt b/White-Sheet/White-Sheet.txt new file mode 100644 index 0000000..e865c86 --- /dev/null +++ b/White-Sheet/White-Sheet.txt @@ -0,0 +1,54 @@ +There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (x2,y2). +After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (x6,y6). + + +Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets. +Input +The first line of the input contains four integers x1,y1,x2,y2 (0≤x1 +using namespace std; + +typedef long long int ll; + + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + ll x11,x12,y11,y12; + ll x21,x22,y21,y22; + ll x31,x32,y31,y32; + + ll area = 0; + + cin>>x11>>y11>>x12>>y12; + cin>>x21>>y21>>x22>>y22; + cin>>x31>>y31>>x32>>y32; + + area = abs(x11-x12)*abs(y11-y12); + x21 = max(x11,x21); + y21 = max(y11,y21); + x22 = min(x12,x22); + y22 = min(y12,y22); + x31 = max(x11,x31); + y31 = max(y11,y31); + x32 = min(x12,x32); + y32 = min(y12,y32); + ll a1,a2,b1,b2; + if(x21 < x22 && y21 < y22) area -= abs(x21-x22)*abs(y21-y22); + if(x31 < x32 && y31 < y32) area -= abs(x31-x32)*abs(y31-y32); + if((x21x31) || (x21x32)) + { + if((y21 < y31 && y22 > y31) || (y21 < y32 && y22 > y32)) + { + ll narea = 0; + + } + } + + a1 = max(x21,x31); + b1 = max(y21,y31); + a2 = min(x22,x32); + b2 = min(y22,y32); + + if(a1 < a2 && b1 < b2) area += abs(a2-a1)*abs(b2-b1); + + if(area > 0) cout<<"YES\n"; + else cout<<"NO\n"; + + return 0; +} \ No newline at end of file From db7026c74cc9b89b8f112622b0e13c91418714d5 Mon Sep 17 00:00:00 2001 From: rohitsh16 Date: Tue, 15 Oct 2019 09:38:25 +0530 Subject: [PATCH 18/47] added prime_subsequence --- Prime_subsequence/question.txt | 10 +++++++++ Prime_subsequence/solution.cpp | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Prime_subsequence/question.txt create mode 100644 Prime_subsequence/solution.cpp diff --git a/Prime_subsequence/question.txt b/Prime_subsequence/question.txt new file mode 100644 index 0000000..b91d65a --- /dev/null +++ b/Prime_subsequence/question.txt @@ -0,0 +1,10 @@ + +Given a sequence of prime numbers A1,A2,…,AN. This sequence has exactly 2N subsequences. +A subsequence of A is good if it does not contain any two identical numbers; in particular, the empty sequence is good. + +You to find the number of good subsequences which contain at most K numbers. +This number could be very large, so compute it modulo 1,000,000,007. + +Constraints: +1≤K≤N≤105 +2≤Ai≤8,000 for each valid i diff --git a/Prime_subsequence/solution.cpp b/Prime_subsequence/solution.cpp new file mode 100644 index 0000000..09cc920 --- /dev/null +++ b/Prime_subsequence/solution.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int main(){ + ios_base::sync_with_stdio(false); + int n,k;cin>>n>>k; + int a[n];long long int mod=1000000007; + int max=0; + for(int i=0;i>a[i]; + if(a[i]>max) + max=a[i]; + } + long int f[max+1]; + memset(f,0,sizeof(f)); + for(int i=0;iv; + for(int i=0;i<=max;i++) + if(f[i]) + v.push_back(f[i]); + long int l=v.size(); + k=k>l?l:k; + long int dpans[k+1][l],val; + val=v[0]+1; + memset(dpans,0,sizeof(dpans)); + dpans[0][0]=1; + dpans[1][0]=val; + long int total=0; + for(int i=2;i<=k;i++) + dpans[i][0]=val; + for(int i=1;i Date: Tue, 15 Oct 2019 11:50:57 +0530 Subject: [PATCH 19/47] Delete PATTERN2.CPP --- PATTERN2.CPP | 81 ---------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 PATTERN2.CPP diff --git a/PATTERN2.CPP b/PATTERN2.CPP deleted file mode 100644 index 18a269d..0000000 --- a/PATTERN2.CPP +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -void main() -{ - clrscr(); - int n,i,j,k; - cout<<"Enter Value Of n: "; - cin>>n; - int space=n-1; - for(i=1; i<=n;i++) - { - cout<=1;k--) - { - cout<<" "; - } - space--; - for(j=1; j<=i; j++) - cout<=1; j--) - cout<>n; - space=n-1; - for(i=1; i<=n;i++) - { - cout<=1;k--) - cout<<" "; - for (j=1; j<=(2*i)-1; j++) - cout<<'*'; - space--; - } - space=1; - for (i=1; i<=n-1; i++) - { - cout<=1; k--) - cout<<" "; - for(j=1;j<=2*(n-i)-1;j++) - cout<<'*'; - space++; - } - getch(); -} - -/* -Enter Value Of n: 5 - - - 1 - 121 - 12321 - 1234321 -123454321 - -Enter Value Of n: 6 - - * - *** - ***** - ******* - ********* -*********** - ********* - ******* - ***** - *** - * - -*/ - - - - - - From b3c2adcd63aa8b49b1c0804515d225cf7fae9e5c Mon Sep 17 00:00:00 2001 From: Kashinath Patekar <42115482+helix026@users.noreply.github.com> Date: Wed, 16 Oct 2019 06:41:47 +0530 Subject: [PATCH 20/47] Add O(sqrt n) solution in JS --- Is prime?/solution.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Is prime?/solution.js diff --git a/Is prime?/solution.js b/Is prime?/solution.js new file mode 100644 index 0000000..292a44a --- /dev/null +++ b/Is prime?/solution.js @@ -0,0 +1,12 @@ +function isPrime(n) { + if(n<2) return false + let prime = true + for (let i = 2; i*i<= n; i++) { + if( n%i == 0) { + prime = false + break + } + } + + return prime +} From 58f8a6a1c5365937c70b23c9e517bb4dd7b263d0 Mon Sep 17 00:00:00 2001 From: Lakshay Agarwal Date: Wed, 16 Oct 2019 20:44:02 +0530 Subject: [PATCH 21/47] Added triplet_problem --- triplet_problem/question.txt | 1 + triplet_problem/solution.c | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 triplet_problem/question.txt create mode 100644 triplet_problem/solution.c diff --git a/triplet_problem/question.txt b/triplet_problem/question.txt new file mode 100644 index 0000000..b1417a8 --- /dev/null +++ b/triplet_problem/question.txt @@ -0,0 +1 @@ +Find a triplet such that sum of two equals to third element in an array. diff --git a/triplet_problem/solution.c b/triplet_problem/solution.c new file mode 100644 index 0000000..69ac10c --- /dev/null +++ b/triplet_problem/solution.c @@ -0,0 +1,48 @@ +#include + +void sort(int a[],int); +void findtriplet(int a[],int n) +{ + sort(a,n); + for(int k=n-1;k>=0;k--) + { + int i=0,j=k-1; + while(i (a[i]+a[j])) + i++; + else + j--; + } + } + printf("No such triplet exists\n"); +} + +void sort(int a[],int n) +{ + for(int i=0;i a[j+1]) + { + int t; + t = a[j]; + a[j] = a[j+1]; + a[j+1] = t; + } + } + } +} + +int main() +{ + int a[9] = {5,32,1,7,10,50,15,21,2}; + findtriplet(a,9); + return 0; +} From 92f40d9cd7eb6091cf2e7d29c8bbae665e2b2a18 Mon Sep 17 00:00:00 2001 From: ameerasherin98 <56751656+ameerasherin98@users.noreply.github.com> Date: Sat, 19 Oct 2019 12:21:10 +0530 Subject: [PATCH 22/47] Update Source1.cpp --- Check_String_Palindrome/Source1.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Check_String_Palindrome/Source1.cpp b/Check_String_Palindrome/Source1.cpp index 0fdda1d..8585e70 100644 --- a/Check_String_Palindrome/Source1.cpp +++ b/Check_String_Palindrome/Source1.cpp @@ -3,6 +3,7 @@ using namespace std; +//This is a function that returns a boolean value, after checking the string. bool checkStringPallindrome(string inputString); bool checkStringPallindrome(string inputString) { @@ -13,10 +14,11 @@ bool checkStringPallindrome(string inputString) { } return true; } -int main() { +void main() { - string input; - getline(cin, input); + clrscr(); //this inbuild function clears the screen + string input; //the string to check whether its palindrome or not + getline(cin, input); if (checkStringPallindrome(input)) { cout << "true" << endl; } @@ -24,6 +26,5 @@ int main() { cout << "false" << endl; } - system("pause"); - return 1; -} \ No newline at end of file + getch(); +} From d2481e91162e6fc647191e2cf36184ad1a552793 Mon Sep 17 00:00:00 2001 From: pmm3 Date: Sat, 19 Oct 2019 14:04:38 -0400 Subject: [PATCH 23/47] Add Buy and sell stock atmost k times for a maximum profit --- .../buyAndSellStock.py | 40 +++++++++++++++++++ .../problem-statement.txt | 9 +++++ 2 files changed, 49 insertions(+) create mode 100644 Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py create mode 100644 Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py b/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py new file mode 100644 index 0000000..729a2a8 --- /dev/null +++ b/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py @@ -0,0 +1,40 @@ +''' +Ref: https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-k-times/ + +''' +# Python program to maximize the profit +# by doing at most k transactions +# given stock prices for n days + +# Function to find out maximum profit by +# buying & selling a share atmost k times +# given stock price of n days +def maxProfit(prices, n, k): + + # Bottom-up DP approach + profit = [[0 for i in range(k + 1)] + for j in range(n)] + + # Profit is zero for the first + # day and for zero transactions + for i in range(1, n): + + for j in range(1, k + 1): + max_so_far = 0 + + for l in range(i): + max_so_far = max(max_so_far, prices[i] - + prices[l] + profit[l][j - 1]) + + profit[i][j] = max(profit[i - 1][j], max_so_far) + + return profit[n - 1][k] + +# Driver code +k = 2 +prices = [10, 22, 5, 75, 65, 80] +n = len(prices) + +print("Maximum profit is:", + maxProfit(prices, n, k)) + diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt b/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt new file mode 100644 index 0000000..3d45433 --- /dev/null +++ b/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt @@ -0,0 +1,9 @@ +Ref: https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-k-times/ + + +In share trading, a buyer buys shares and sells on a future date. Given the stock price of n days, the trader is allowed to make at most k transactions, where a new transaction can only start after the previous transaction is complete, find out the maximum profit that a share trader could have made. + +There are various versions of the problem. If we are allowed to buy and sell only once, then we can use Maximum difference between two elements algorithm. If we are allowed to make at most 2 transactions, we can follow approach discussed here. + +In this case, we are only allowed to make at max k transactions. The problem can be solved by using dynamic programming. + From 7a9946b9edb1e70db112d2dd3b389ad63bde982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 12:42:04 -0300 Subject: [PATCH 24/47] Add txt file --- .../Biggest_Sum_5_Consecutives_Integers | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers diff --git a/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers b/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers new file mode 100644 index 0000000..b526a8c --- /dev/null +++ b/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers @@ -0,0 +1,19 @@ +What's the biggest sum you can get from adding 5 consecutives integers in a array? + +Example: + Array = [1, 3, -2, 4, -9, 1, 4, 7] + Possibles Sums: + 1 + 3 + (-2) + 4 + (-9) = -3 + 3 + (-2) + 4 + (-9) + 1 = -3 + (-2) + 4 + (-9) + 1 + 4 = -2 + 4 + (-9) + 1 + 4 + 7 = 7 + + So the biggest Sum is 7. + +What's the biggest sum of 5 consecutives integers of the array below? + +Array = [1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, + 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2 + 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5,7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1] + +PS: There may or may not have different sequences that has the same sum. From f58a99ef90389f588fef76c1f0daff93d75d0b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 12:42:25 -0300 Subject: [PATCH 25/47] add solution --- .../solution.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Biggest_Sum_5_Consecutives_Integers/solution.c diff --git a/Biggest_Sum_5_Consecutives_Integers/solution.c b/Biggest_Sum_5_Consecutives_Integers/solution.c new file mode 100644 index 0000000..086bd3f --- /dev/null +++ b/Biggest_Sum_5_Consecutives_Integers/solution.c @@ -0,0 +1,23 @@ +#include +#include + +int main(){ + int i; + int size = 81; //SIZE OF THE ARRAY + int sum; + int biggestSum; + int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; + + //FIRST SUM + sum = array[0] + array[1] + array[2] + array[3] + array[4]; + biggestSum = sum; + + //OTHER SUMS + for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 + sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER + if(sum > biggestSum){ + biggestSum = sum; + } + } + printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT +} \ No newline at end of file From d30a57161eb6131f8cdcab07a1b440a752b00ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 13:00:01 -0300 Subject: [PATCH 26/47] Added txt --- CollatzConjecture/CollatzConjecture.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CollatzConjecture/CollatzConjecture.txt diff --git a/CollatzConjecture/CollatzConjecture.txt b/CollatzConjecture/CollatzConjecture.txt new file mode 100644 index 0000000..799a6b3 --- /dev/null +++ b/CollatzConjecture/CollatzConjecture.txt @@ -0,0 +1,24 @@ +Collatz Conjecture + +The Collatz Conjecture says that if you take any number and follow the following steps, you will never be stuck in a loop. + +If the number is even -> number = number/2; +If the number is odd -> number = 3*number + 1; + +If you continue to do this, at some point your number will be equal to 1. + +Example: number = 26 + 1 Step - number = 26/2 = 13 + 2 Step - number = 13*3 + 1 = 40 + 3 Step - number = 40/2 = 20 + 4 Step - number = 20/2 = 10 + 5 Step - number = 10/2 = 5 + 6 Step - number = 3*5 + 1 = 16 + 7 Step - number = 16/2 = 8 + 8 Step - number = 8/2 = 4 + 9 Step - number = 4/2 = 2 + 10 Step - number = 2/2 = 1 + +For the number 26, 10 steps are needed, create a solution that calculates the number of steps for a given N number, +and the biggest value the number had during the steps. + From a30538d52aee7d760262b5e8bf244ead343d91f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 13:00:40 -0300 Subject: [PATCH 27/47] Added .c --- CollatzConjecture/solution.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CollatzConjecture/solution.c diff --git a/CollatzConjecture/solution.c b/CollatzConjecture/solution.c new file mode 100644 index 0000000..600e64a --- /dev/null +++ b/CollatzConjecture/solution.c @@ -0,0 +1,23 @@ +#include +#include + +int main(){ + long int N = 26; //CALCULATING FOR N = 26 + long int biggestValue = 0; + long int steps = 0; + + while(N != 1){ + if(N%2 == 0){ + N = N/2; + }else{ + N = N*3 + 1; + } + if(N>biggestValue){ + biggestValue = N; + } + steps++; + } + + printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); + +} \ No newline at end of file From a810f74458ca08fcfe32d2b06f180657e86d82eb Mon Sep 17 00:00:00 2001 From: Ayman Azzam Date: Tue, 22 Oct 2019 23:40:46 +0200 Subject: [PATCH 28/47] Industrial Nim is added --- Industrial Nim/Industrial_Nim.cpp | 35 +++++++++++++++++++++++++++++++ Industrial Nim/Industrial_Nim.txt | 29 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Industrial Nim/Industrial_Nim.cpp create mode 100644 Industrial Nim/Industrial_Nim.txt diff --git a/Industrial Nim/Industrial_Nim.cpp b/Industrial Nim/Industrial_Nim.cpp new file mode 100644 index 0000000..680db05 --- /dev/null +++ b/Industrial Nim/Industrial_Nim.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +vector vec; +bool nim() /* return true if the first player will win */ +{ + long long x=0; + for(int i=0;i0; +} + +long long f(long long n) /* n&3 equivalent to n%4 */ +{ + long long x=n&3; + if(x==0) return n; if(x==1) return 1; + if(x==2) return n+1; if(x==3) return 0; +} + + + +int main() +{ + long long n,x,m; + cin>>n; + while(n--) + { + cin>>x>>m; + vec.push_back(f(x+m-1)^f(x-1)); + } + if(nim()) + cout<<"tolik"< Date: Thu, 1 Oct 2020 01:54:53 +0530 Subject: [PATCH 29/47] Create question 1408A.txt --- Circle Coloring/question 1408A.txt | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Circle Coloring/question 1408A.txt diff --git a/Circle Coloring/question 1408A.txt b/Circle Coloring/question 1408A.txt new file mode 100644 index 0000000..d412d68 --- /dev/null +++ b/Circle Coloring/question 1408A.txt @@ -0,0 +1,82 @@ + CIRCLE COLORING + time limit per test1 second + memory limit per test256 megabytes + inputstandard input + outputstandard output + +You are given three sequences: a1,a2,…,an; b1,b2,…,bn; c1,c2,…,cn. + +For each i, ai≠bi, ai≠ci, bi≠ci. + +Find a sequence p1,p2,…,pn, that satisfy the following conditions: + +piâ{ai,bi,ci} +pi≠p(imodn)+1. +In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements i,i+1 adjacent for i Date: Thu, 1 Oct 2020 01:55:32 +0530 Subject: [PATCH 30/47] Create 1408A.cpp --- Circle Coloring/1408A.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Circle Coloring/1408A.cpp diff --git a/Circle Coloring/1408A.cpp b/Circle Coloring/1408A.cpp new file mode 100644 index 0000000..d526a08 --- /dev/null +++ b/Circle Coloring/1408A.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int main() +{ + while() + { + int n; + cin>>n; + std::vector a(n), b(n), c(n), ans; + + for(int i=0; i>a[i]; + } + for(int i=0; i>b[i]; + } + for(int i=0; i>c[i]; + } + ans.push_back(a[0]); + + for(int i=1; i Date: Sat, 10 Oct 2020 00:11:34 +0530 Subject: [PATCH 31/47] Delete problem.txt --- Is prime?/problem.txt | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 Is prime?/problem.txt diff --git a/Is prime?/problem.txt b/Is prime?/problem.txt deleted file mode 100644 index 7357bc2..0000000 --- a/Is prime?/problem.txt +++ /dev/null @@ -1,9 +0,0 @@ -Implement a function that determines if a given positive integer is a prime or not. - -Example - -For n = 47, the output should be -isPrime(n) = true; - -For n = 4, the output should be -isPrime(n) = false; \ No newline at end of file From b9bea4939ab98176de3c427768ce1d5d585c2f84 Mon Sep 17 00:00:00 2001 From: Parth Chauhan <35137224+chauhanparth210@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:11:56 +0530 Subject: [PATCH 32/47] Delete solution.hs --- Is prime?/solution.hs | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Is prime?/solution.hs diff --git a/Is prime?/solution.hs b/Is prime?/solution.hs deleted file mode 100644 index 05b33bc..0000000 --- a/Is prime?/solution.hs +++ /dev/null @@ -1 +0,0 @@ -isPrime n = length (filter (==0) (map (mod n) [1..n])) == 2 \ No newline at end of file From 127d349a6c00a08cad6cd3d046335a875635608d Mon Sep 17 00:00:00 2001 From: Parth Chauhan <35137224+chauhanparth210@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:12:16 +0530 Subject: [PATCH 33/47] Delete solution.js --- Is prime?/solution.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 Is prime?/solution.js diff --git a/Is prime?/solution.js b/Is prime?/solution.js deleted file mode 100644 index 292a44a..0000000 --- a/Is prime?/solution.js +++ /dev/null @@ -1,12 +0,0 @@ -function isPrime(n) { - if(n<2) return false - let prime = true - for (let i = 2; i*i<= n; i++) { - if( n%i == 0) { - prime = false - break - } - } - - return prime -} From b2c35f11b247233f554e07508d9a1087a676420a Mon Sep 17 00:00:00 2001 From: chauhanparth210 <00chauhanparth@gmail.com> Date: Sat, 10 Oct 2020 00:20:07 +0530 Subject: [PATCH 34/47] is_prime is added by stellarbeam and jonathan-sh --- is_prime/problem.txt | 9 +++++++++ is_prime/solution.hs | 1 + is_prime/solution.js | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 is_prime/problem.txt create mode 100644 is_prime/solution.hs create mode 100644 is_prime/solution.js diff --git a/is_prime/problem.txt b/is_prime/problem.txt new file mode 100644 index 0000000..3ca919e --- /dev/null +++ b/is_prime/problem.txt @@ -0,0 +1,9 @@ +Implement a function that determines if a given positive integer is a prime or not. + +Example + +For n = 47, the output should be +isPrime(n) = true; + +For n = 4, the output should be +isPrime(n) = false; diff --git a/is_prime/solution.hs b/is_prime/solution.hs new file mode 100644 index 0000000..05b33bc --- /dev/null +++ b/is_prime/solution.hs @@ -0,0 +1 @@ +isPrime n = length (filter (==0) (map (mod n) [1..n])) == 2 \ No newline at end of file diff --git a/is_prime/solution.js b/is_prime/solution.js new file mode 100644 index 0000000..714c8f7 --- /dev/null +++ b/is_prime/solution.js @@ -0,0 +1,12 @@ +function isPrime(n) { + if(n<2) return false + let prime = true + for (let i = 2; i*i<= n; i++) { + if( n%i == 0) { + prime = false + break + } + } + + return prime +} \ No newline at end of file From 2f1de3ea241e1608127bcd994d01f12e2ab0fbb3 Mon Sep 17 00:00:00 2001 From: chauhanparth210 <00chauhanparth@gmail.com> Date: Sat, 10 Oct 2020 00:35:49 +0530 Subject: [PATCH 35/47] topic wise folders --- {FCFS => Algorithm/FCFS}/fcfs.py | 0 {FCFS => Algorithm/FCFS}/question.txt | 0 .../Floodfill}/Problem_statement.txt | 56 ++--- .../Floodfill}/solution.java | 106 +++++----- .../Floodfill}/solution.py | 0 .../Josephus's Problem}/josephus.java | 0 .../Josephus's Problem}/question.txt | 0 .../Kadane's Algorithm}/kadane.c | 72 +++---- .../Kadane's Algorithm}/kadane.cpp | 0 .../Kadane's Algorithm}/kadane.py | 0 .../Kadane's Algorithm}/problem.txt | 10 +- .../hot_potato}/hot_potato.cpp | 0 .../hot_potato}/question.txt | 0 {nQueen => Algorithm/nQueen}/Question.txt | 0 {nQueen => Algorithm/nQueen}/nQueen.cpp | 180 ++++++++-------- .../Biggest_Sum_5_Consecutives_Integers | 0 .../solution.c | 44 ++-- .../Circle Coloring}/1408A.cpp | 0 .../Circle Coloring}/question 1408A.txt | 0 .../Lily's Homework}/Question.txt | 20 +- .../Lily's Homework}/solution.py | 52 ++--- .../Mislove Has Lost an Array}/Question.txt | 0 .../Mislove Has Lost an Array}/Solution.cpp | 0 .../Omar and Candies}/Problem Statement.txt | 0 .../Omar and Candies}/Solution.c | 0 .../Philosophers_Stone}/question.txt | 0 .../Philosophers_Stone}/solution.cpp | 0 .../Phone price}/solution.cpp | 0 .../Phone price}/statement.txt | 0 .../Sieve of Eratosthenes}/Question.txt | 0 .../Sieve of Eratosthenes}/Solution.cpp | 0 {TRUEDARE => Array/TRUEDARE}/QUESTION.txt | 0 {TRUEDARE => Array/TRUEDARE}/SOLUTION.txt | 0 .../White-Sheet}/White-Sheet.txt | 106 +++++----- {White-Sheet => Array/White-Sheet}/code.cpp | 0 .../triplet_problem}/question.txt | 0 .../triplet_problem}/solution.c | 0 .../SudokuSolver}/Question.txt | 0 .../SudokuSolver}/sudokuSolver.cpp | 200 +++++++++--------- .../Armstrong No}/armstrongnum.c | 0 .../Average}/Average-Question.txt | 0 {Average => Basic Math/Average}/Solution.cpp | 0 .../counting.txt | 0 .../Counting-Change-Combinations}/solution.js | 0 .../Divisibility_Check}/Question.txt | 0 .../Divisibility_Check}/Solution.cpp | 0 .../Problem Description.txt | 4 +- .../Divisible Sum Pairs}/solution.js | 24 +-- .../Fizz Buzz}/c#_solution.cs | 0 .../Fizz Buzz}/dart_solution.dart | 26 +-- .../Fizz Buzz}/fizzbuzz.c | 24 +-- .../Fizz Buzz}/fizzbuzz.cpp | 32 +-- .../Fizz Buzz}/instructions.txt | 0 .../Fizz Buzz}/javascript_solution.js | 0 .../Fizz Buzz}/php_solution.php | 0 .../Fizz Buzz}/python_solution.py | 0 .../Fizz Buzz}/ruby_solution.rb | 0 {is_prime => Basic Math/Is prime}/problem.txt | 2 +- {is_prime => Basic Math/Is prime}/solution.hs | 0 {is_prime => Basic Math/Is prime}/solution.js | 2 +- .../Least_Common_Multiple}/LCM.cbl | 0 .../Least_Common_Multiple}/Problem.txt | 0 .../Octal Decimal Calculator.txt | 16 +- .../OctalDecimalCalculator.java | 86 ++++---- .../.idea/Odd or Even Game.iml | 0 .../Odd or Even Game}/.idea/misc.xml | 0 .../Odd or Even Game}/.idea/modules.xml | 0 .../Odd or Even Game}/.idea/vcs.xml | 0 .../Odd or Even Game}/.idea/workspace.xml | 0 .../Odd or Even Game}/OddEvenGame.txt | 0 .../Odd or Even Game}/oddEvenGame.py | 0 {PROXY => Basic Math/PROXY}/question.txt | 0 {PROXY => Basic Math/PROXY}/solution.cpp | 0 .../Prime_gen}/Prime Generator(prime_gen) | 0 .../Prime_gen}/prime_gen.cpp | 0 .../Save the Prisoner!}/question.txt | 0 .../Save the Prisoner!}/solution.cpp | 0 .../Sherlock-and-the-beast-problem.md | 0 .../Sherlock-and-the-beast}/solution.cpp | 130 ++++++------ .../The Additionator}/The Additionator.txt | 0 .../The Additionator}/solution.java | 0 .../The Prime Game}/Problem_statement.txt | 16 +- .../The Prime Game}/Solution.py | 24 +-- .../problem_statement.txt | 0 .../when to take medicine_answer.txt | 0 .../find_factorial_of_a_number.txt | 0 .../find_factorial_of_a_number}/solution.cpp | 0 .../Highly divisible triangular number.cpp | 0 .../project_euler problem12}/problem | 0 .../CollatzConjecture}/CollatzConjecture.txt | 0 .../CollatzConjecture}/solution.c | 44 ++-- .../EncoderProblem}/Encoder.java | 0 .../EncoderProblem}/problem.txt | 0 .../Leap Year}/instructions.txt | 0 .../Leap Year}/ruby_solution.rb | 0 .../Sleep_In}/sleep_in.py | 0 .../hacktoberfest-loop.txt | 0 .../infinity-hscktoberfest-loop.py | 0 .../problem statement.txt | 0 .../Aggressive Cows Spoj}/solution1.cpp | 0 .../Aggressive Cows Spoj}/solution2.cpp | 0 .../binary_search}/binary_search.txt | 0 .../binary_search}/bs.class | Bin .../binary_search}/bs.ctxt | 0 .../binary_search}/bs.java | 0 .../binary_search}/solution.cpp | 0 .../binary_search}/solution.py | 0 .../ZOMCAV}/ZOMCAV.txt | 0 .../ZOMCAV}/codechef.class | Bin .../ZOMCAV}/codechef.ctxt | 0 .../ZOMCAV}/codechef.java | 0 .../0-1 Knapsack Problem}/Question.txt | 0 .../0-1 Knapsack Problem}/Solution.c | 0 .../buyAndSellStock.py | 0 .../problem-statement.txt | 0 .../Bytelandian-gold-coins}/instructions.txt | 0 .../Bytelandian-gold-coins}/solution.cpp | 0 .../COINS}/Question.txt | 0 .../COINS}/Readme.md | 0 .../COINS}/Solution.cpp | 0 .../Min Steps to 1 Problem Statement.txt | 0 .../DP- Min Steps to 1}/minsteps.java | 0 .../Magic-Spells-LCS}/problem.txt | 0 .../Magic-Spells-LCS}/solution.cpp | 0 .../Max_Sum_Contiguous_Subarray}/Question.txt | 0 .../Max_Sum_Contiguous_Subarray}/Readme.md | 0 .../Max_Sum_Contiguous_Subarray}/Solution.cpp | 0 .../Maximize the product.txt | 0 .../Maximize the Product}/solution.cpp | 0 .../Maximum sum of digits}/code.cpp | 0 .../problem_statement.txt | 0 .../Maximum-Perimeter-Triangle-Problem | 0 .../Maximum-Perimeter-Triangle}/Solution.cpp | 0 .../Powerset}/powerset.js | 0 .../Powerset}/question.txt | 0 .../Prime_subsequence}/question.txt | 0 .../Prime_subsequence}/solution.cpp | 0 .../ROCK}/problem.txt | 0 {ROCK => Dynamic Programming/ROCK}/rock.cpp | 0 .../Rod cutting problem}/question.txt | 0 .../Rod cutting problem}/solution.java | 0 .../mailbox-question.txt | 0 .../solution.cpp | 0 .../Zero_Sum_SubArray}/question.txt | 0 .../Zero_Sum_SubArray}/solution.cpp | 0 .../alphacode}/problem_statement.txt | 0 .../alphacode}/solution.txt | 0 .../question.txt | 0 .../solution.cpp | 0 .../Problem_Statement.txt | 0 .../The_Coin_Change_Problem}/Solution.java | 0 .../Problem Statement.txt | 0 .../Solution.cpp | 0 {AAL => Patterns/AAL}/Aditya And Ladders.txt | 0 {AAL => Patterns/AAL}/x.cpp | 0 .../PatternPrinting}/README.md | 0 .../PatternPrinting}/sum.java | 70 +++--- .../SpiralMatrix}/problem.txt | 0 .../SpiralMatrix}/solution.cpp | 0 README.md | 17 +- .../Factorial using recursion.cpp | 0 .../Factorial using Recursion}/Question.txt | 0 .../Tower-of-Hanoi}/Hanoi.java | 0 .../Tower-of-Hanoi}/Tower of Hanoi.txt | 0 .../problem_statement.txt | 0 .../In search of an easy problem}/sol.cpp | 0 .../SGU_weeds_344}/weed.cpp | 0 .../SGU_weeds_344}/weed.txt | 0 .../Get Longest Sorted Sequence}/answer.py | 0 .../Get Longest Sorted Sequence}/problem.txt | 0 .../insertion_sort.cpp | 0 .../Insertion_sort_using_classes}/problem.txt | 0 .../Mergesort-JS}/mergeSort.js | 0 .../Mergesort-JS}/question.txt | 0 .../Merging_Two_Sorted_Array}/question.txt | 0 .../Merging_Two_Sorted_Array}/solution.cpp | 0 .../Mersort_In_C++}/mergeSort.cpp | 156 +++++++------- .../Mersort_In_C++}/mergesort.txt | 0 .../Quicksort-JS}/question.txt | 0 .../Quicksort-JS}/quickSort.js | 0 .../Quicksort-python}/Question.txt | 0 .../Quicksort-python}/algorithm.txt | 0 .../Quicksort-python}/quickSort.py | 0 .../bubble_sort_c}/question.txt | 0 .../bubble_sort_c}/solution/bubble_sort.c | 0 .../bubble_sort_c}/solution/bubble_sort.h | 0 .../bubble_sort_c}/solution/main.c | 0 .../bubble_sort_c}/solution/print_array.c | 0 .../Generate Parentheses}/Question.txt | 0 .../Generate Parentheses}/Solution | Bin .../Generate Parentheses}/Solution.cpp | 0 .../Street parade}/code.cpp | 0 .../Street parade}/problem_statement.txt | 0 .../AnagramChecking}/anagram_checking.py | 0 .../AnagramChecking}/anagram_checking.txt | 0 .../Arrangement_of_Queue}/Question.txt | 0 .../Arrangement_of_Queue}/README.md | 0 .../Arrangement_of_Queue}/Solution.py | 0 .../Cenit-Polar-Crypt}/Issue.txt | 0 .../Cenit-Polar-Crypt}/Solution.js | 0 .../Check_String_Palindrome}/Source1.cpp | 0 .../Check_String_Palindrome}/problem.txt | 0 {FANCY => String/FANCY}/problem.txt | 0 {FANCY => String/FANCY}/solution.py | 0 {Isograms => String/Isograms}/isograms.py | 0 .../Isograms}/problem_statement.txt | 0 .../Palindrome}/palindrome.c | 0 .../Palindrome}/question.txt | 0 .../Python_Palindrome}/PalindromeQues.txt | 0 .../Python_Palindrome}/solution.py | 0 .../Reverse string in place}/question.txt | 0 .../Reverse string in place}/solution.java | 0 .../ReverseChars}/ReverseChars.java | 50 ++--- .../ReverseChars}/problem.txt | 0 .../SplitString}/Question.txt | 0 .../SplitString}/Solution.cpp | 0 .../String_Permutation}/question.txt | 0 .../String_Permutation}/solution.cpp | 0 .../StrongPassword}/solution.py | 0 .../StrongPassword}/strongpasswordqn.txt | 0 .../Subsequences}/question.txt | 0 .../Subsequences}/subsequences.cpp | 54 ++--- .../The Reversed World}/Solution.cpp | 0 .../The Reversed World.txt | 0 .../ToyObsession}/problem.c | 0 .../ToyObsession}/solution.c | 0 .../Word_Frequency}/question.txt | 0 .../Word_Frequency}/solution.js | 0 {ginortS => String/ginortS}/Question.txt | 0 {ginortS => String/ginortS}/Solution.py | 0 .../size-of-tree-C++}/problem_statement.txt | 0 .../size-of-tree-C++}/sizeoftree.cpp | 0 {Acronym => Unknown/Acronym}/instructions.txt | 0 {Acronym => Unknown/Acronym}/ruby_solution.rb | 0 {CONTON => Unknown/CONTON}/QUESTION.txt | 0 {CONTON => Unknown/CONTON}/solution.c | 0 {Chefdil => Unknown/Chefdil}/ans.cpp | 0 {Chefdil => Unknown/Chefdil}/ques.txt | 0 .../Chocolate_SPOJ}/question.txt | 0 .../Chocolate_SPOJ}/solution.java | 0 .../Fair Rations}/Answer.cpp | 0 .../Fair Rations}/Problem Statement .txt | 0 .../Industrial Nim}/Industrial_Nim.cpp | 0 .../Industrial Nim}/Industrial_Nim.txt | 0 {Necklace => Unknown/Necklace}/solution.cpp | 0 {Necklace => Unknown/Necklace}/statement.pdf | Bin {PINS => Unknown/PINS}/problem.txt | 0 {PINS => Unknown/PINS}/solution.cpp | 0 {PolyMul => Unknown/PolyMul}/question.txt | 0 {PolyMul => Unknown/PolyMul}/solution.cpp | 0 .../Strange_Food_Chain}/question.txt | 0 .../Strange_Food_Chain}/solution.cpp | 0 {WATCHFB => Unknown/WATCHFB}/Main.class | Bin {WATCHFB => Unknown/WATCHFB}/Main.ctxt | 0 {WATCHFB => Unknown/WATCHFB}/Main.java | 0 {WATCHFB => Unknown/WATCHFB}/WATCHFB.txt | 0 .../chusky_adventurer}/problem_statement.txt | 0 .../chusky_adventurer}/solution.cpp | 0 .../chusky_hunger}/problem_statement.txt | 0 .../chusky_hunger}/solution.cpp | 0 .../chusky_nightgame}/problem_statement.txt | 0 .../chusky_nightgame}/solution.cpp | 0 .../coin-piles}/problem_statement.txt | 0 .../coin-piles}/solution.cpp | 0 264 files changed, 818 insertions(+), 805 deletions(-) rename {FCFS => Algorithm/FCFS}/fcfs.py (100%) rename {FCFS => Algorithm/FCFS}/question.txt (100%) rename {Floodfill => Algorithm/Floodfill}/Problem_statement.txt (97%) rename {Floodfill => Algorithm/Floodfill}/solution.java (95%) rename {Floodfill => Algorithm/Floodfill}/solution.py (100%) rename {Josephus's Problem => Algorithm/Josephus's Problem}/josephus.java (100%) rename {Josephus's Problem => Algorithm/Josephus's Problem}/question.txt (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.c (95%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.cpp (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.py (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/problem.txt (96%) rename {hot_potato => Algorithm/hot_potato}/hot_potato.cpp (100%) rename {hot_potato => Algorithm/hot_potato}/question.txt (100%) rename {nQueen => Algorithm/nQueen}/Question.txt (100%) rename {nQueen => Algorithm/nQueen}/nQueen.cpp (96%) mode change 100755 => 100644 rename {Biggest_Sum_5_Consecutives_Integers => Array/Biggest_Sum_5_Consecutives_Integers}/Biggest_Sum_5_Consecutives_Integers (100%) rename {Biggest_Sum_5_Consecutives_Integers => Array/Biggest_Sum_5_Consecutives_Integers}/solution.c (97%) rename {Circle Coloring => Array/Circle Coloring}/1408A.cpp (100%) rename {Circle Coloring => Array/Circle Coloring}/question 1408A.txt (100%) rename {Lily's Homework => Array/Lily's Homework}/Question.txt (98%) rename {Lily's Homework => Array/Lily's Homework}/solution.py (96%) rename {Mislove Has Lost an Array => Array/Mislove Has Lost an Array}/Question.txt (100%) rename {Mislove Has Lost an Array => Array/Mislove Has Lost an Array}/Solution.cpp (100%) rename {Omar and Candies => Array/Omar and Candies}/Problem Statement.txt (100%) rename {Omar and Candies => Array/Omar and Candies}/Solution.c (100%) rename {Philosophers_Stone => Array/Philosophers_Stone}/question.txt (100%) rename {Philosophers_Stone => Array/Philosophers_Stone}/solution.cpp (100%) rename {Phone price => Array/Phone price}/solution.cpp (100%) rename {Phone price => Array/Phone price}/statement.txt (100%) rename {Sieve of Eratosthenes => Array/Sieve of Eratosthenes}/Question.txt (100%) rename {Sieve of Eratosthenes => Array/Sieve of Eratosthenes}/Solution.cpp (100%) rename {TRUEDARE => Array/TRUEDARE}/QUESTION.txt (100%) rename {TRUEDARE => Array/TRUEDARE}/SOLUTION.txt (100%) rename {White-Sheet => Array/White-Sheet}/White-Sheet.txt (97%) rename {White-Sheet => Array/White-Sheet}/code.cpp (100%) rename {triplet_problem => Array/triplet_problem}/question.txt (100%) rename {triplet_problem => Array/triplet_problem}/solution.c (100%) rename {SudokuSolver => Backtracking/SudokuSolver}/Question.txt (100%) rename {SudokuSolver => Backtracking/SudokuSolver}/sudokuSolver.cpp (95%) mode change 100755 => 100644 rename {Armstrong No => Basic Math/Armstrong No}/armstrongnum.c (100%) rename {Average => Basic Math/Average}/Average-Question.txt (100%) rename {Average => Basic Math/Average}/Solution.cpp (100%) rename {Counting-Change-Combinations => Basic Math/Counting-Change-Combinations}/counting.txt (100%) rename {Counting-Change-Combinations => Basic Math/Counting-Change-Combinations}/solution.js (100%) rename {Divisibility_Check => Basic Math/Divisibility_Check}/Question.txt (100%) rename {Divisibility_Check => Basic Math/Divisibility_Check}/Solution.cpp (100%) rename {Divisible Sum Pairs => Basic Math/Divisible Sum Pairs}/Problem Description.txt (98%) rename {Divisible Sum Pairs => Basic Math/Divisible Sum Pairs}/solution.js (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/c#_solution.cs (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/dart_solution.dart (94%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/fizzbuzz.c (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/fizzbuzz.cpp (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/instructions.txt (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/javascript_solution.js (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/php_solution.php (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/python_solution.py (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/ruby_solution.rb (100%) rename {is_prime => Basic Math/Is prime}/problem.txt (89%) rename {is_prime => Basic Math/Is prime}/solution.hs (100%) rename {is_prime => Basic Math/Is prime}/solution.js (99%) rename {Least_Common_Multiple => Basic Math/Least_Common_Multiple}/LCM.cbl (100%) rename {Least_Common_Multiple => Basic Math/Least_Common_Multiple}/Problem.txt (100%) rename {Octal Decimal Calculator => Basic Math/Octal Decimal Calculator}/Octal Decimal Calculator.txt (97%) rename {Octal Decimal Calculator => Basic Math/Octal Decimal Calculator}/OctalDecimalCalculator.java (96%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/Odd or Even Game.iml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/misc.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/modules.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/vcs.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/workspace.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/OddEvenGame.txt (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/oddEvenGame.py (100%) rename {PROXY => Basic Math/PROXY}/question.txt (100%) rename {PROXY => Basic Math/PROXY}/solution.cpp (100%) rename {Prime_gen => Basic Math/Prime_gen}/Prime Generator(prime_gen) (100%) rename {Prime_gen => Basic Math/Prime_gen}/prime_gen.cpp (100%) rename {Save the Prisoner! => Basic Math/Save the Prisoner!}/question.txt (100%) rename {Save the Prisoner! => Basic Math/Save the Prisoner!}/solution.cpp (100%) rename {Sherlock-and-the-beast => Basic Math/Sherlock-and-the-beast}/Sherlock-and-the-beast-problem.md (100%) rename {Sherlock-and-the-beast => Basic Math/Sherlock-and-the-beast}/solution.cpp (94%) rename {The Additionator => Basic Math/The Additionator}/The Additionator.txt (100%) rename {The Additionator => Basic Math/The Additionator}/solution.java (100%) rename {The Prime Game => Basic Math/The Prime Game}/Problem_statement.txt (99%) rename {The Prime Game => Basic Math/The Prime Game}/Solution.py (96%) rename {When to take medicine => Basic Math/When to take medicine}/problem_statement.txt (100%) rename {When to take medicine => Basic Math/When to take medicine}/when to take medicine_answer.txt (100%) rename {find_factorial_of_a_number => Basic Math/find_factorial_of_a_number}/find_factorial_of_a_number.txt (100%) rename {find_factorial_of_a_number => Basic Math/find_factorial_of_a_number}/solution.cpp (100%) rename {project_euler problem12 => Basic Math/project_euler problem12}/Highly divisible triangular number.cpp (100%) rename {project_euler problem12 => Basic Math/project_euler problem12}/problem (100%) rename {CollatzConjecture => Basic Program/CollatzConjecture}/CollatzConjecture.txt (100%) rename {CollatzConjecture => Basic Program/CollatzConjecture}/solution.c (95%) rename {EncoderProblem => Basic Program/EncoderProblem}/Encoder.java (100%) rename {EncoderProblem => Basic Program/EncoderProblem}/problem.txt (100%) rename {Leap Year => Basic Program/Leap Year}/instructions.txt (100%) rename {Leap Year => Basic Program/Leap Year}/ruby_solution.rb (100%) rename {Sleep_In => Basic Program/Sleep_In}/sleep_in.py (100%) rename {how-can-create-a-hackthoberfest-infinite-loop-in-python => Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python}/hacktoberfest-loop.txt (100%) rename {how-can-create-a-hackthoberfest-infinite-loop-in-python => Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python}/infinity-hscktoberfest-loop.py (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/problem statement.txt (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/solution1.cpp (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/solution2.cpp (100%) rename {binary_search => Binary Search/binary_search}/binary_search.txt (100%) rename {binary_search => Binary Search/binary_search}/bs.class (100%) rename {binary_search => Binary Search/binary_search}/bs.ctxt (100%) rename {binary_search => Binary Search/binary_search}/bs.java (100%) rename {binary_search => Binary Search/binary_search}/solution.cpp (100%) rename {binary_search => Binary Search/binary_search}/solution.py (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/ZOMCAV.txt (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.class (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.ctxt (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.java (100%) rename {0-1 Knapsack Problem => Dynamic Programming/0-1 Knapsack Problem}/Question.txt (100%) rename {0-1 Knapsack Problem => Dynamic Programming/0-1 Knapsack Problem}/Solution.c (100%) rename {Buy-and-Sell-Stock-for-Maximum-Profit => Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit}/buyAndSellStock.py (100%) rename {Buy-and-Sell-Stock-for-Maximum-Profit => Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit}/problem-statement.txt (100%) rename {Bytelandian-gold-coins => Dynamic Programming/Bytelandian-gold-coins}/instructions.txt (100%) rename {Bytelandian-gold-coins => Dynamic Programming/Bytelandian-gold-coins}/solution.cpp (100%) rename {COINS => Dynamic Programming/COINS}/Question.txt (100%) rename {COINS => Dynamic Programming/COINS}/Readme.md (100%) rename {COINS => Dynamic Programming/COINS}/Solution.cpp (100%) rename {DP- Min Steps to 1 => Dynamic Programming/DP- Min Steps to 1}/Min Steps to 1 Problem Statement.txt (100%) rename {DP- Min Steps to 1 => Dynamic Programming/DP- Min Steps to 1}/minsteps.java (100%) rename {Magic-Spells-LCS => Dynamic Programming/Magic-Spells-LCS}/problem.txt (100%) rename {Magic-Spells-LCS => Dynamic Programming/Magic-Spells-LCS}/solution.cpp (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Question.txt (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Readme.md (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Solution.cpp (100%) rename {Maximize the Product => Dynamic Programming/Maximize the Product}/Maximize the product.txt (100%) rename {Maximize the Product => Dynamic Programming/Maximize the Product}/solution.cpp (100%) rename {Maximum sum of digits => Dynamic Programming/Maximum sum of digits}/code.cpp (100%) rename {Maximum sum of digits => Dynamic Programming/Maximum sum of digits}/problem_statement.txt (100%) rename {Maximum-Perimeter-Triangle => Dynamic Programming/Maximum-Perimeter-Triangle}/Maximum-Perimeter-Triangle-Problem (100%) rename {Maximum-Perimeter-Triangle => Dynamic Programming/Maximum-Perimeter-Triangle}/Solution.cpp (100%) rename {Powerset => Dynamic Programming/Powerset}/powerset.js (100%) rename {Powerset => Dynamic Programming/Powerset}/question.txt (100%) rename {Prime_subsequence => Dynamic Programming/Prime_subsequence}/question.txt (100%) rename {Prime_subsequence => Dynamic Programming/Prime_subsequence}/solution.cpp (100%) rename {ROCK => Dynamic Programming/ROCK}/problem.txt (100%) rename {ROCK => Dynamic Programming/ROCK}/rock.cpp (100%) rename {Rod cutting problem => Dynamic Programming/Rod cutting problem}/question.txt (100%) rename {Rod cutting problem => Dynamic Programming/Rod cutting problem}/solution.java (100%) rename {The Mailbox Manufacturers Problem => Dynamic Programming/The Mailbox Manufacturers Problem}/mailbox-question.txt (100%) rename {The Mailbox Manufacturers Problem => Dynamic Programming/The Mailbox Manufacturers Problem}/solution.cpp (100%) rename {Zero_Sum_SubArray => Dynamic Programming/Zero_Sum_SubArray}/question.txt (100%) rename {Zero_Sum_SubArray => Dynamic Programming/Zero_Sum_SubArray}/solution.cpp (100%) rename {alphacode => Dynamic Programming/alphacode}/problem_statement.txt (100%) rename {alphacode => Dynamic Programming/alphacode}/solution.txt (100%) rename {Product_of_lengths_all_cycles_undirected_graph => Graph/Product_of_lengths_all_cycles_undirected_graph}/question.txt (100%) rename {Product_of_lengths_all_cycles_undirected_graph => Graph/Product_of_lengths_all_cycles_undirected_graph}/solution.cpp (100%) rename {The_Coin_Change_Problem => Greedy/The_Coin_Change_Problem}/Problem_Statement.txt (100%) rename {The_Coin_Change_Problem => Greedy/The_Coin_Change_Problem}/Solution.java (100%) rename {Implement a Line Editor with a Linked List => LinkedList/Implement a Line Editor with a Linked List}/Problem Statement.txt (100%) rename {Implement a Line Editor with a Linked List => LinkedList/Implement a Line Editor with a Linked List}/Solution.cpp (100%) rename {AAL => Patterns/AAL}/Aditya And Ladders.txt (100%) rename {AAL => Patterns/AAL}/x.cpp (100%) rename {PatternPrinting => Patterns/PatternPrinting}/README.md (100%) rename {PatternPrinting => Patterns/PatternPrinting}/sum.java (95%) rename {SpiralMatrix => Patterns/SpiralMatrix}/problem.txt (100%) rename {SpiralMatrix => Patterns/SpiralMatrix}/solution.cpp (100%) rename {Factorial using Recursion => Recursion/Factorial using Recursion}/Factorial using recursion.cpp (100%) rename {Factorial using Recursion => Recursion/Factorial using Recursion}/Question.txt (100%) rename {Tower-of-Hanoi => Recursion/Tower-of-Hanoi}/Hanoi.java (100%) rename {Tower-of-Hanoi => Recursion/Tower-of-Hanoi}/Tower of Hanoi.txt (100%) rename {In search of an easy problem => Searching/In search of an easy problem}/problem_statement.txt (100%) rename {In search of an easy problem => Searching/In search of an easy problem}/sol.cpp (100%) rename {SGU_weeds_344 => Searching/SGU_weeds_344}/weed.cpp (100%) rename {SGU_weeds_344 => Searching/SGU_weeds_344}/weed.txt (100%) rename {Get Longest Sorted Sequence => Sorting/Get Longest Sorted Sequence}/answer.py (100%) rename {Get Longest Sorted Sequence => Sorting/Get Longest Sorted Sequence}/problem.txt (100%) rename {Insertion_sort_using_classes => Sorting/Insertion_sort_using_classes}/insertion_sort.cpp (100%) rename {Insertion_sort_using_classes => Sorting/Insertion_sort_using_classes}/problem.txt (100%) rename {Mergesort-JS => Sorting/Mergesort-JS}/mergeSort.js (100%) rename {Mergesort-JS => Sorting/Mergesort-JS}/question.txt (100%) rename {Merging_Two_Sorted_Array => Sorting/Merging_Two_Sorted_Array}/question.txt (100%) rename {Merging_Two_Sorted_Array => Sorting/Merging_Two_Sorted_Array}/solution.cpp (100%) rename {Mersort_In_C++ => Sorting/Mersort_In_C++}/mergeSort.cpp (94%) mode change 100755 => 100644 rename {Mersort_In_C++ => Sorting/Mersort_In_C++}/mergesort.txt (100%) rename {Quicksort-JS => Sorting/Quicksort-JS}/question.txt (100%) rename {Quicksort-JS => Sorting/Quicksort-JS}/quickSort.js (100%) rename {Quicksort-python => Sorting/Quicksort-python}/Question.txt (100%) rename {Quicksort-python => Sorting/Quicksort-python}/algorithm.txt (100%) rename {Quicksort-python => Sorting/Quicksort-python}/quickSort.py (100%) mode change 100755 => 100644 rename {bubble_sort_c => Sorting/bubble_sort_c}/question.txt (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/bubble_sort.c (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/bubble_sort.h (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/main.c (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/print_array.c (100%) rename {Generate Parentheses => Stack/Generate Parentheses}/Question.txt (100%) rename {Generate Parentheses => Stack/Generate Parentheses}/Solution (100%) mode change 100755 => 100644 rename {Generate Parentheses => Stack/Generate Parentheses}/Solution.cpp (100%) rename {Street parade => Stack/Street parade}/code.cpp (100%) rename {Street parade => Stack/Street parade}/problem_statement.txt (100%) rename {AnagramChecking => String/AnagramChecking}/anagram_checking.py (100%) mode change 100755 => 100644 rename {AnagramChecking => String/AnagramChecking}/anagram_checking.txt (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/Question.txt (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/README.md (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/Solution.py (100%) rename {Cenit-Polar-Crypt => String/Cenit-Polar-Crypt}/Issue.txt (100%) rename {Cenit-Polar-Crypt => String/Cenit-Polar-Crypt}/Solution.js (100%) rename {Check_String_Palindrome => String/Check_String_Palindrome}/Source1.cpp (100%) rename {Check_String_Palindrome => String/Check_String_Palindrome}/problem.txt (100%) rename {FANCY => String/FANCY}/problem.txt (100%) rename {FANCY => String/FANCY}/solution.py (100%) rename {Isograms => String/Isograms}/isograms.py (100%) rename {Isograms => String/Isograms}/problem_statement.txt (100%) rename {Palindrome => String/Palindrome}/palindrome.c (100%) rename {Palindrome => String/Palindrome}/question.txt (100%) rename {Python_Palindrome => String/Python_Palindrome}/PalindromeQues.txt (100%) rename {Python_Palindrome => String/Python_Palindrome}/solution.py (100%) rename {Reverse string in place => String/Reverse string in place}/question.txt (100%) rename {Reverse string in place => String/Reverse string in place}/solution.java (100%) rename {ReverseChars => String/ReverseChars}/ReverseChars.java (95%) rename {ReverseChars => String/ReverseChars}/problem.txt (100%) rename {SplitString => String/SplitString}/Question.txt (100%) rename {SplitString => String/SplitString}/Solution.cpp (100%) rename {String_Permutation => String/String_Permutation}/question.txt (100%) rename {String_Permutation => String/String_Permutation}/solution.cpp (100%) rename {StrongPassword => String/StrongPassword}/solution.py (100%) rename {StrongPassword => String/StrongPassword}/strongpasswordqn.txt (100%) rename {Subsequences => String/Subsequences}/question.txt (100%) rename {Subsequences => String/Subsequences}/subsequences.cpp (94%) mode change 100755 => 100644 rename {The Reversed World => String/The Reversed World}/Solution.cpp (100%) rename {The Reversed World => String/The Reversed World}/The Reversed World.txt (100%) rename {ToyObsession => String/ToyObsession}/problem.c (100%) rename {ToyObsession => String/ToyObsession}/solution.c (100%) rename {Word_Frequency => String/Word_Frequency}/question.txt (100%) rename {Word_Frequency => String/Word_Frequency}/solution.js (100%) rename {ginortS => String/ginortS}/Question.txt (100%) rename {ginortS => String/ginortS}/Solution.py (100%) rename {size-of-tree-C++ => Tree/size-of-tree-C++}/problem_statement.txt (100%) rename {size-of-tree-C++ => Tree/size-of-tree-C++}/sizeoftree.cpp (100%) rename {Acronym => Unknown/Acronym}/instructions.txt (100%) rename {Acronym => Unknown/Acronym}/ruby_solution.rb (100%) rename {CONTON => Unknown/CONTON}/QUESTION.txt (100%) rename {CONTON => Unknown/CONTON}/solution.c (100%) rename {Chefdil => Unknown/Chefdil}/ans.cpp (100%) rename {Chefdil => Unknown/Chefdil}/ques.txt (100%) rename {Chocolate_SPOJ => Unknown/Chocolate_SPOJ}/question.txt (100%) rename {Chocolate_SPOJ => Unknown/Chocolate_SPOJ}/solution.java (100%) rename {Fair Rations => Unknown/Fair Rations}/Answer.cpp (100%) rename {Fair Rations => Unknown/Fair Rations}/Problem Statement .txt (100%) rename {Industrial Nim => Unknown/Industrial Nim}/Industrial_Nim.cpp (100%) rename {Industrial Nim => Unknown/Industrial Nim}/Industrial_Nim.txt (100%) rename {Necklace => Unknown/Necklace}/solution.cpp (100%) rename {Necklace => Unknown/Necklace}/statement.pdf (100%) rename {PINS => Unknown/PINS}/problem.txt (100%) rename {PINS => Unknown/PINS}/solution.cpp (100%) rename {PolyMul => Unknown/PolyMul}/question.txt (100%) rename {PolyMul => Unknown/PolyMul}/solution.cpp (100%) rename {Strange_Food_Chain => Unknown/Strange_Food_Chain}/question.txt (100%) rename {Strange_Food_Chain => Unknown/Strange_Food_Chain}/solution.cpp (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.class (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.ctxt (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.java (100%) rename {WATCHFB => Unknown/WATCHFB}/WATCHFB.txt (100%) rename {chusky_adventurer => Unknown/chusky_adventurer}/problem_statement.txt (100%) rename {chusky_adventurer => Unknown/chusky_adventurer}/solution.cpp (100%) rename {chusky_hunger => Unknown/chusky_hunger}/problem_statement.txt (100%) rename {chusky_hunger => Unknown/chusky_hunger}/solution.cpp (100%) rename {chusky_nightgame => Unknown/chusky_nightgame}/problem_statement.txt (100%) rename {chusky_nightgame => Unknown/chusky_nightgame}/solution.cpp (100%) rename {coin-piles => Unknown/coin-piles}/problem_statement.txt (100%) rename {coin-piles => Unknown/coin-piles}/solution.cpp (100%) diff --git a/FCFS/fcfs.py b/Algorithm/FCFS/fcfs.py similarity index 100% rename from FCFS/fcfs.py rename to Algorithm/FCFS/fcfs.py diff --git a/FCFS/question.txt b/Algorithm/FCFS/question.txt similarity index 100% rename from FCFS/question.txt rename to Algorithm/FCFS/question.txt diff --git a/Floodfill/Problem_statement.txt b/Algorithm/Floodfill/Problem_statement.txt similarity index 97% rename from Floodfill/Problem_statement.txt rename to Algorithm/Floodfill/Problem_statement.txt index 9ddda57..f36d41a 100644 --- a/Floodfill/Problem_statement.txt +++ b/Algorithm/Floodfill/Problem_statement.txt @@ -1,28 +1,28 @@ -For those who don’t like regular images, ASCII Maps Inc. has created maps that are fully printable ASCII characters. Each map is a rectangular grid of lowercase English letters, where each letter stands for various locations. In particular, ‘w’ stands for water and the other 25 letters represent various different land locations. For this problem, we are interested in counting the number of bodies of water on a given ASCII map. A body of water is a maximal set of contiguous grid squares on the ASCII map where each square in the body of water shares a boundary with at least one other square in the body of water. Thus, for two grid squares to be part of the same body of water, one must be above, below, to the left, or to the right of the other grid square. -Input -The first line of input consists of two space separated integers, r (1=r=50) and c (1=c=50), the number of rows and columns, respectively for the input map. The next r lines will each contain c lowercase English letters, representing the corresponding row of the input map. - -Output -On a line by itself, output the number of bodies of water in the input map. - -Sample test case 1: - -Input: -5 6 -waaaww -wawawc -bbbbwc -wwwwww -dddddd - -Output: -3 - -Sample test case 2: -Input: -2 8 -wxwxwxwx -xwxwxwxw - -Output: -8 +For those who don’t like regular images, ASCII Maps Inc. has created maps that are fully printable ASCII characters. Each map is a rectangular grid of lowercase English letters, where each letter stands for various locations. In particular, ‘w’ stands for water and the other 25 letters represent various different land locations. For this problem, we are interested in counting the number of bodies of water on a given ASCII map. A body of water is a maximal set of contiguous grid squares on the ASCII map where each square in the body of water shares a boundary with at least one other square in the body of water. Thus, for two grid squares to be part of the same body of water, one must be above, below, to the left, or to the right of the other grid square. +Input +The first line of input consists of two space separated integers, r (1=r=50) and c (1=c=50), the number of rows and columns, respectively for the input map. The next r lines will each contain c lowercase English letters, representing the corresponding row of the input map. + +Output +On a line by itself, output the number of bodies of water in the input map. + +Sample test case 1: + +Input: +5 6 +waaaww +wawawc +bbbbwc +wwwwww +dddddd + +Output: +3 + +Sample test case 2: +Input: +2 8 +wxwxwxwx +xwxwxwxw + +Output: +8 diff --git a/Floodfill/solution.java b/Algorithm/Floodfill/solution.java similarity index 95% rename from Floodfill/solution.java rename to Algorithm/Floodfill/solution.java index 2974a5a..a043c94 100644 --- a/Floodfill/solution.java +++ b/Algorithm/Floodfill/solution.java @@ -1,53 +1,53 @@ -import java.util.Arrays; -import java.util.Scanner; - -public class water { -public static void main(String[] args){ -Scanner kb=new Scanner(System.in); -System.out.println("Enter the dimensions of the map:"); -int n=kb.nextInt(); -int m=kb.nextInt(); -System.out.println("Enter the map:"); -char[][] x=new char[n][m]; -for(int i=0;i=0&&r=0&&c=0&&r=0&&c -#include - -int maxSubarraySum(int a[], int l) { - int max = INT_MIN, max_here = 0; - - for (int i = 0; i < l; i++) { - max_here = max_here + a[i]; - if (max < max_here) max = max_here; - if (max_here < 0) max_here = 0; - } - - return max; -} - -// int maxSubarraySum(int a[], int l) { -// int max = a[0], max_here = a[0]; - -// for (int i = 0; i < l; i++) { -// if (max_here > 0) max_here += a[i]; -// else max_here = a[i]; -// if (max_here > max) max = max_here; -// } - -// return max; -// } - -int main(int argc, char *argv[]) { - int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}; - int l = sizeof(arr) / sizeof(int); - - int m = maxSubarraySum(arr, l); - - printf("%d is the max subarray sum\n", m); - - return 0; +#include +#include + +int maxSubarraySum(int a[], int l) { + int max = INT_MIN, max_here = 0; + + for (int i = 0; i < l; i++) { + max_here = max_here + a[i]; + if (max < max_here) max = max_here; + if (max_here < 0) max_here = 0; + } + + return max; +} + +// int maxSubarraySum(int a[], int l) { +// int max = a[0], max_here = a[0]; + +// for (int i = 0; i < l; i++) { +// if (max_here > 0) max_here += a[i]; +// else max_here = a[i]; +// if (max_here > max) max = max_here; +// } + +// return max; +// } + +int main(int argc, char *argv[]) { + int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}; + int l = sizeof(arr) / sizeof(int); + + int m = maxSubarraySum(arr, l); + + printf("%d is the max subarray sum\n", m); + + return 0; } \ No newline at end of file diff --git a/Kadane's Algorithm/kadane.cpp b/Algorithm/Kadane's Algorithm/kadane.cpp similarity index 100% rename from Kadane's Algorithm/kadane.cpp rename to Algorithm/Kadane's Algorithm/kadane.cpp diff --git a/Kadane's Algorithm/kadane.py b/Algorithm/Kadane's Algorithm/kadane.py similarity index 100% rename from Kadane's Algorithm/kadane.py rename to Algorithm/Kadane's Algorithm/kadane.py diff --git a/Kadane's Algorithm/problem.txt b/Algorithm/Kadane's Algorithm/problem.txt similarity index 96% rename from Kadane's Algorithm/problem.txt rename to Algorithm/Kadane's Algorithm/problem.txt index ad9467e..1f05316 100644 --- a/Kadane's Algorithm/problem.txt +++ b/Algorithm/Kadane's Algorithm/problem.txt @@ -1,5 +1,5 @@ -Problem: -Find out the maximum continuous subarray sum in linear time - -Solution: -Kadane's algorithm can calculate the maximum subarray sum in linear time +Problem: +Find out the maximum continuous subarray sum in linear time + +Solution: +Kadane's algorithm can calculate the maximum subarray sum in linear time diff --git a/hot_potato/hot_potato.cpp b/Algorithm/hot_potato/hot_potato.cpp similarity index 100% rename from hot_potato/hot_potato.cpp rename to Algorithm/hot_potato/hot_potato.cpp diff --git a/hot_potato/question.txt b/Algorithm/hot_potato/question.txt similarity index 100% rename from hot_potato/question.txt rename to Algorithm/hot_potato/question.txt diff --git a/nQueen/Question.txt b/Algorithm/nQueen/Question.txt similarity index 100% rename from nQueen/Question.txt rename to Algorithm/nQueen/Question.txt diff --git a/nQueen/nQueen.cpp b/Algorithm/nQueen/nQueen.cpp old mode 100755 new mode 100644 similarity index 96% rename from nQueen/nQueen.cpp rename to Algorithm/nQueen/nQueen.cpp index 0cfd39c..505b926 --- a/nQueen/nQueen.cpp +++ b/Algorithm/nQueen/nQueen.cpp @@ -1,90 +1,90 @@ - -#include -using namespace std; - -char board[30][30]; - -void printBoard(char arr[][30], int n) { - for (int r = 0; r < n; ++r) { - for (int c = 0; c < n; ++c) { - cout << arr[r][c] << " " ; - } - cout << endl; - } -} - -void initialiseBoard(int n) { - for (int r = 0; r < n; ++r) { - for (int c = 0; c < n; ++c) { - board[r][c] = 'X'; - } - } -} - -bool canPlace(char board[][30], int N, int x, int y) -{ - //check the row if aqueen already exists - for (int r = 0; r < N; ++r) - { - if (board[r][y] == 'Q') - return false; - } - - int rInc[] = { -1, +1, +1, -1}; - int cInc[] = { -1, +1, -1, +1}; - //check diagonal if queen already exists - for (int dir = 0; dir < 4; ++dir) - { - int rowAdd = rInc[dir]; - int colAdd = cInc[dir]; - int r = x + rowAdd; - int c = y + colAdd; - //check that r c is within the board - while (r >= 0 && r < N && c >= 0 && c < N) - { - if (board[r][c] == 'Q') - return false; - r = r + rowAdd; - c = c + colAdd; - } - } - return true; -} - -bool nqueen(int r, int n) -{ - if (r == n)//base case if all queens are placed - { - return true; - } - //for every column, use hit and trial by placing a queen in the each cell of curr Row - for (int c = 0; c < n; ++c) - { - int x = r; - int y = c; - //check if queen can be placed on board[i][c] - if (canPlace(board, n, x, y)==true) - { - board[x][y] = 'Q'; //place queen in each column - bool isSuccessful = nqueen(r + 1, n); //recursion to place rest of queens - if (isSuccessful == true) - return true; - board[x][y] = 'X'; //else unmark the cell or backtrack - } - } - return false; //if queen cannot be placed in any row in this column then return false -} - -int main() -{ - int n; - cin >> n; - - initialiseBoard(n);//initialse all the board with X - bool isSuccessful = nqueen(0, n); - - if (isSuccessful) printBoard(board, n); - else cout << "Sorry man! You need to have a larger board!\n"; - - return 0; -} + +#include +using namespace std; + +char board[30][30]; + +void printBoard(char arr[][30], int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + cout << arr[r][c] << " " ; + } + cout << endl; + } +} + +void initialiseBoard(int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + board[r][c] = 'X'; + } + } +} + +bool canPlace(char board[][30], int N, int x, int y) +{ + //check the row if aqueen already exists + for (int r = 0; r < N; ++r) + { + if (board[r][y] == 'Q') + return false; + } + + int rInc[] = { -1, +1, +1, -1}; + int cInc[] = { -1, +1, -1, +1}; + //check diagonal if queen already exists + for (int dir = 0; dir < 4; ++dir) + { + int rowAdd = rInc[dir]; + int colAdd = cInc[dir]; + int r = x + rowAdd; + int c = y + colAdd; + //check that r c is within the board + while (r >= 0 && r < N && c >= 0 && c < N) + { + if (board[r][c] == 'Q') + return false; + r = r + rowAdd; + c = c + colAdd; + } + } + return true; +} + +bool nqueen(int r, int n) +{ + if (r == n)//base case if all queens are placed + { + return true; + } + //for every column, use hit and trial by placing a queen in the each cell of curr Row + for (int c = 0; c < n; ++c) + { + int x = r; + int y = c; + //check if queen can be placed on board[i][c] + if (canPlace(board, n, x, y)==true) + { + board[x][y] = 'Q'; //place queen in each column + bool isSuccessful = nqueen(r + 1, n); //recursion to place rest of queens + if (isSuccessful == true) + return true; + board[x][y] = 'X'; //else unmark the cell or backtrack + } + } + return false; //if queen cannot be placed in any row in this column then return false +} + +int main() +{ + int n; + cin >> n; + + initialiseBoard(n);//initialse all the board with X + bool isSuccessful = nqueen(0, n); + + if (isSuccessful) printBoard(board, n); + else cout << "Sorry man! You need to have a larger board!\n"; + + return 0; +} diff --git a/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers b/Array/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers similarity index 100% rename from Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers rename to Array/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers diff --git a/Biggest_Sum_5_Consecutives_Integers/solution.c b/Array/Biggest_Sum_5_Consecutives_Integers/solution.c similarity index 97% rename from Biggest_Sum_5_Consecutives_Integers/solution.c rename to Array/Biggest_Sum_5_Consecutives_Integers/solution.c index 086bd3f..4a395d4 100644 --- a/Biggest_Sum_5_Consecutives_Integers/solution.c +++ b/Array/Biggest_Sum_5_Consecutives_Integers/solution.c @@ -1,23 +1,23 @@ -#include -#include - -int main(){ - int i; - int size = 81; //SIZE OF THE ARRAY - int sum; - int biggestSum; - int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; - - //FIRST SUM - sum = array[0] + array[1] + array[2] + array[3] + array[4]; - biggestSum = sum; - - //OTHER SUMS - for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 - sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER - if(sum > biggestSum){ - biggestSum = sum; - } - } - printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT +#include +#include + +int main(){ + int i; + int size = 81; //SIZE OF THE ARRAY + int sum; + int biggestSum; + int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; + + //FIRST SUM + sum = array[0] + array[1] + array[2] + array[3] + array[4]; + biggestSum = sum; + + //OTHER SUMS + for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 + sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER + if(sum > biggestSum){ + biggestSum = sum; + } + } + printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT } \ No newline at end of file diff --git a/Circle Coloring/1408A.cpp b/Array/Circle Coloring/1408A.cpp similarity index 100% rename from Circle Coloring/1408A.cpp rename to Array/Circle Coloring/1408A.cpp diff --git a/Circle Coloring/question 1408A.txt b/Array/Circle Coloring/question 1408A.txt similarity index 100% rename from Circle Coloring/question 1408A.txt rename to Array/Circle Coloring/question 1408A.txt diff --git a/Lily's Homework/Question.txt b/Array/Lily's Homework/Question.txt similarity index 98% rename from Lily's Homework/Question.txt rename to Array/Lily's Homework/Question.txt index 502c95c..39f207f 100644 --- a/Lily's Homework/Question.txt +++ b/Array/Lily's Homework/Question.txt @@ -1,11 +1,11 @@ -Consider an array of distinct integers, arr = [a[0], a[1], ..., a[n-1]]. George can swap any two elements of the array any number of times. An array is beautiful if the sum of |arr[i] - arr[i-1]|among 0< i < n is minimal. - -Given the array , determine and return the minimum number of swaps that should be performed in order to make the array beautiful. - -For example, arr = [7, 15, 12, 3]. One minimal array is [3, 7, 12, 15]. To get there, George performed the following swaps: - -Swap Result - [7, 15, 12, 3] -3 7 [3, 15, 12, 7] -7 15 [3, 7, 12, 15] +Consider an array of distinct integers, arr = [a[0], a[1], ..., a[n-1]]. George can swap any two elements of the array any number of times. An array is beautiful if the sum of |arr[i] - arr[i-1]|among 0< i < n is minimal. + +Given the array , determine and return the minimum number of swaps that should be performed in order to make the array beautiful. + +For example, arr = [7, 15, 12, 3]. One minimal array is [3, 7, 12, 15]. To get there, George performed the following swaps: + +Swap Result + [7, 15, 12, 3] +3 7 [3, 15, 12, 7] +7 15 [3, 7, 12, 15] It took 2 swaps to make the array beautiful. This is minimal among the choice of beautiful arrays possible. \ No newline at end of file diff --git a/Lily's Homework/solution.py b/Array/Lily's Homework/solution.py similarity index 96% rename from Lily's Homework/solution.py rename to Array/Lily's Homework/solution.py index 8b29419..7783d49 100644 --- a/Lily's Homework/solution.py +++ b/Array/Lily's Homework/solution.py @@ -1,26 +1,26 @@ -def lilysHomework(arr): - m = {} - for i in range(len(arr)): - m[arr[i]] = i - sorted_arr = sorted(arr) - res = 0 - for i in range(len(arr)): - if(arr[i] != sorted_arr[i]): - res += 1 - x = m[sorted_arr[i]] - m[ arr[i] ] = m[ sorted_arr[i]] - arr[i],arr[x] = sorted_arr[i],arr[i] - return res - -if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') - - n = int(input()) - - arr = list(map(int, input().rstrip().split())) - - result = min(lilysHomework(list(arr)), lilysHomework(list(arr[::-1]))) - - fptr.write(str(result) + '\n') - - fptr.close() +def lilysHomework(arr): + m = {} + for i in range(len(arr)): + m[arr[i]] = i + sorted_arr = sorted(arr) + res = 0 + for i in range(len(arr)): + if(arr[i] != sorted_arr[i]): + res += 1 + x = m[sorted_arr[i]] + m[ arr[i] ] = m[ sorted_arr[i]] + arr[i],arr[x] = sorted_arr[i],arr[i] + return res + +if __name__ == '__main__': + fptr = open(os.environ['OUTPUT_PATH'], 'w') + + n = int(input()) + + arr = list(map(int, input().rstrip().split())) + + result = min(lilysHomework(list(arr)), lilysHomework(list(arr[::-1]))) + + fptr.write(str(result) + '\n') + + fptr.close() diff --git a/Mislove Has Lost an Array/Question.txt b/Array/Mislove Has Lost an Array/Question.txt similarity index 100% rename from Mislove Has Lost an Array/Question.txt rename to Array/Mislove Has Lost an Array/Question.txt diff --git a/Mislove Has Lost an Array/Solution.cpp b/Array/Mislove Has Lost an Array/Solution.cpp similarity index 100% rename from Mislove Has Lost an Array/Solution.cpp rename to Array/Mislove Has Lost an Array/Solution.cpp diff --git a/Omar and Candies/Problem Statement.txt b/Array/Omar and Candies/Problem Statement.txt similarity index 100% rename from Omar and Candies/Problem Statement.txt rename to Array/Omar and Candies/Problem Statement.txt diff --git a/Omar and Candies/Solution.c b/Array/Omar and Candies/Solution.c similarity index 100% rename from Omar and Candies/Solution.c rename to Array/Omar and Candies/Solution.c diff --git a/Philosophers_Stone/question.txt b/Array/Philosophers_Stone/question.txt similarity index 100% rename from Philosophers_Stone/question.txt rename to Array/Philosophers_Stone/question.txt diff --git a/Philosophers_Stone/solution.cpp b/Array/Philosophers_Stone/solution.cpp similarity index 100% rename from Philosophers_Stone/solution.cpp rename to Array/Philosophers_Stone/solution.cpp diff --git a/Phone price/solution.cpp b/Array/Phone price/solution.cpp similarity index 100% rename from Phone price/solution.cpp rename to Array/Phone price/solution.cpp diff --git a/Phone price/statement.txt b/Array/Phone price/statement.txt similarity index 100% rename from Phone price/statement.txt rename to Array/Phone price/statement.txt diff --git a/Sieve of Eratosthenes/Question.txt b/Array/Sieve of Eratosthenes/Question.txt similarity index 100% rename from Sieve of Eratosthenes/Question.txt rename to Array/Sieve of Eratosthenes/Question.txt diff --git a/Sieve of Eratosthenes/Solution.cpp b/Array/Sieve of Eratosthenes/Solution.cpp similarity index 100% rename from Sieve of Eratosthenes/Solution.cpp rename to Array/Sieve of Eratosthenes/Solution.cpp diff --git a/TRUEDARE/QUESTION.txt b/Array/TRUEDARE/QUESTION.txt similarity index 100% rename from TRUEDARE/QUESTION.txt rename to Array/TRUEDARE/QUESTION.txt diff --git a/TRUEDARE/SOLUTION.txt b/Array/TRUEDARE/SOLUTION.txt similarity index 100% rename from TRUEDARE/SOLUTION.txt rename to Array/TRUEDARE/SOLUTION.txt diff --git a/White-Sheet/White-Sheet.txt b/Array/White-Sheet/White-Sheet.txt similarity index 97% rename from White-Sheet/White-Sheet.txt rename to Array/White-Sheet/White-Sheet.txt index e865c86..57d317d 100644 --- a/White-Sheet/White-Sheet.txt +++ b/Array/White-Sheet/White-Sheet.txt @@ -1,54 +1,54 @@ -There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (x2,y2). -After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (x6,y6). - - -Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets. -Input -The first line of the input contains four integers x1,y1,x2,y2 (0≤x1 -#include -using namespace std; - -void print2D(int arr[][20], int M, int N) { - for (int i = 0; i < M; ++i) { - for (int j = 0; j < N; ++j) { - cout << arr[i][j] << " "; - } - cout << endl; - } -} - -bool myfixed[20][20] = {}; - -void input2D_soduku(int arr[][20], int M, int N) -{ - for (int i = 0; i < M; ++i) - { - for (int j = 0; j < N; ++j) - { - cin >> arr[i][j]; - if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change - } - } -} - -bool canPlace(int board[][20], int N, int x, int y, int num) -{ - //check along row && col - for (int i = 0; i < N; ++i) - { - if (board[x][i] == num) return false; //check along row - if (board[i][y] == num) return false; //check along col - } - - //check in the box - int rootN = sqrt(N); - int boxRow = x / rootN; - int boxCol = y / rootN; - int startRow = boxRow * rootN; - int startCol = boxCol * rootN; - - for (int r = startRow; r < startRow + rootN; ++r) - { - for (int c = startCol; c < startCol + rootN; ++c) - { - if (board[r][c] == num) return false; - } - } - - return true; -} - - -bool solveSudoku(int board[][20], int N, int x, int y) -{ - if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over - - if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row - - if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); - - for (int num = 1; num <= N; ++num) - { - if (canPlace(board, N, x, y, num) == true) - { - board[x][y] = num; - bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns - if (isSuccessful) return true; - else board[x][y] = 0; - } - } - return false; -} - -int main() -{ - int board[20][20] = {}; - - int N; - cin >> N; - input2D_soduku(board, N, N); - for(int i=0;i>board[i][j]; - } - } - cout << "==============\n"; - - print2D(board, N, N); - - cout << "==============\n"; - - solveSudoku(board, N, 0, 0); - - print2D(board, N, N); - -} - +#include +#include +using namespace std; + +void print2D(int arr[][20], int M, int N) { + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + cout << arr[i][j] << " "; + } + cout << endl; + } +} + +bool myfixed[20][20] = {}; + +void input2D_soduku(int arr[][20], int M, int N) +{ + for (int i = 0; i < M; ++i) + { + for (int j = 0; j < N; ++j) + { + cin >> arr[i][j]; + if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change + } + } +} + +bool canPlace(int board[][20], int N, int x, int y, int num) +{ + //check along row && col + for (int i = 0; i < N; ++i) + { + if (board[x][i] == num) return false; //check along row + if (board[i][y] == num) return false; //check along col + } + + //check in the box + int rootN = sqrt(N); + int boxRow = x / rootN; + int boxCol = y / rootN; + int startRow = boxRow * rootN; + int startCol = boxCol * rootN; + + for (int r = startRow; r < startRow + rootN; ++r) + { + for (int c = startCol; c < startCol + rootN; ++c) + { + if (board[r][c] == num) return false; + } + } + + return true; +} + + +bool solveSudoku(int board[][20], int N, int x, int y) +{ + if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over + + if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row + + if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); + + for (int num = 1; num <= N; ++num) + { + if (canPlace(board, N, x, y, num) == true) + { + board[x][y] = num; + bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns + if (isSuccessful) return true; + else board[x][y] = 0; + } + } + return false; +} + +int main() +{ + int board[20][20] = {}; + + int N; + cin >> N; + input2D_soduku(board, N, N); + for(int i=0;i>board[i][j]; + } + } + cout << "==============\n"; + + print2D(board, N, N); + + cout << "==============\n"; + + solveSudoku(board, N, 0, 0); + + print2D(board, N, N); + +} + diff --git a/Armstrong No/armstrongnum.c b/Basic Math/Armstrong No/armstrongnum.c similarity index 100% rename from Armstrong No/armstrongnum.c rename to Basic Math/Armstrong No/armstrongnum.c diff --git a/Average/Average-Question.txt b/Basic Math/Average/Average-Question.txt similarity index 100% rename from Average/Average-Question.txt rename to Basic Math/Average/Average-Question.txt diff --git a/Average/Solution.cpp b/Basic Math/Average/Solution.cpp similarity index 100% rename from Average/Solution.cpp rename to Basic Math/Average/Solution.cpp diff --git a/Counting-Change-Combinations/counting.txt b/Basic Math/Counting-Change-Combinations/counting.txt similarity index 100% rename from Counting-Change-Combinations/counting.txt rename to Basic Math/Counting-Change-Combinations/counting.txt diff --git a/Counting-Change-Combinations/solution.js b/Basic Math/Counting-Change-Combinations/solution.js similarity index 100% rename from Counting-Change-Combinations/solution.js rename to Basic Math/Counting-Change-Combinations/solution.js diff --git a/Divisibility_Check/Question.txt b/Basic Math/Divisibility_Check/Question.txt similarity index 100% rename from Divisibility_Check/Question.txt rename to Basic Math/Divisibility_Check/Question.txt diff --git a/Divisibility_Check/Solution.cpp b/Basic Math/Divisibility_Check/Solution.cpp similarity index 100% rename from Divisibility_Check/Solution.cpp rename to Basic Math/Divisibility_Check/Solution.cpp diff --git a/Divisible Sum Pairs/Problem Description.txt b/Basic Math/Divisible Sum Pairs/Problem Description.txt similarity index 98% rename from Divisible Sum Pairs/Problem Description.txt rename to Basic Math/Divisible Sum Pairs/Problem Description.txt index 7525f0e..1ffa981 100644 --- a/Divisible Sum Pairs/Problem Description.txt +++ b/Basic Math/Divisible Sum Pairs/Problem Description.txt @@ -1,2 +1,2 @@ -You are given an array of n integers, ar = [ar[0], ar[1], ... , ar[n-1]], and a positive integer k. Find and print the number of -(i,j) pairs where i < j and ar[i]+ar[j] is divisible by k. +You are given an array of n integers, ar = [ar[0], ar[1], ... , ar[n-1]], and a positive integer k. Find and print the number of +(i,j) pairs where i < j and ar[i]+ar[j] is divisible by k. diff --git a/Divisible Sum Pairs/solution.js b/Basic Math/Divisible Sum Pairs/solution.js similarity index 95% rename from Divisible Sum Pairs/solution.js rename to Basic Math/Divisible Sum Pairs/solution.js index d75bca6..7c65521 100644 --- a/Divisible Sum Pairs/solution.js +++ b/Basic Math/Divisible Sum Pairs/solution.js @@ -1,12 +1,12 @@ -function divisibleSumPairs(n, k, ar) { - let count =0; - for(let i=0; i -void main() -{ - int i; - for(i=1;i<=100;i++) - { - if(i%3!=0 && i%5!=0) printf("%d\n", i); - if(i%3 == 0 && i%5!=0)printf("Fizz\n"); - if(i%5 == 0 && i%3!=0)printf("Buzz\n"); - if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); - } -} +#include +void main() +{ + int i; + for(i=1;i<=100;i++) + { + if(i%3!=0 && i%5!=0) printf("%d\n", i); + if(i%3 == 0 && i%5!=0)printf("Fizz\n"); + if(i%5 == 0 && i%3!=0)printf("Buzz\n"); + if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); + } +} diff --git a/Fizz Buzz/fizzbuzz.cpp b/Basic Math/Fizz Buzz/fizzbuzz.cpp similarity index 95% rename from Fizz Buzz/fizzbuzz.cpp rename to Basic Math/Fizz Buzz/fizzbuzz.cpp index 22eea15..4d6c904 100644 --- a/Fizz Buzz/fizzbuzz.cpp +++ b/Basic Math/Fizz Buzz/fizzbuzz.cpp @@ -1,16 +1,16 @@ -#include -using namespace std; -int main() -{ - for(int i=1;i<=100;i++){ - if((i%3 == 0) && (i%5==0)) - cout<<"FizzBuzz\n"; - else if(i%3 == 0) - cout<<"Fizz\n"; - else if(i%5 == 0) - cout<<"Buzz\n"; - else - cout< +using namespace std; +int main() +{ + for(int i=1;i<=100;i++){ + if((i%3 == 0) && (i%5==0)) + cout<<"FizzBuzz\n"; + else if(i%3 == 0) + cout<<"Fizz\n"; + else if(i%5 == 0) + cout<<"Buzz\n"; + else + cout< 0; i--) { - caracter = tmp.substring(i-1, i); - multiple = (int) Math.pow(BASE_8, count); - int value = (Integer.parseInt(caracter) * multiple); - count = count + 1; - result += value; - - } - - return String.valueOf(result); - } - -} +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class OctalDecimalCalculator { + + private static int BASE_8 = 8; + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final String RESULT_TEMPLATE = "The decimal number for octal %s is: %s"; + + public static void main(String[] args){ + + System.out.println("Please input octal number to convert"); + try { + String octal = br.readLine(); + String decimal = convertOctalToDecimal(Integer.parseInt(octal)); + + System.out.println(String.format(RESULT_TEMPLATE, octal, decimal)); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public static String convertOctalToDecimal(int octal){ + int result = 0; + String tmp = String.valueOf(octal); + int count = 0; + int multiple; + String caracter; + for (int i = tmp.length(); i > 0; i--) { + caracter = tmp.substring(i-1, i); + multiple = (int) Math.pow(BASE_8, count); + int value = (Integer.parseInt(caracter) * multiple); + count = count + 1; + result += value; + + } + + return String.valueOf(result); + } + +} diff --git a/Odd or Even Game/.idea/Odd or Even Game.iml b/Basic Math/Odd or Even Game/.idea/Odd or Even Game.iml similarity index 100% rename from Odd or Even Game/.idea/Odd or Even Game.iml rename to Basic Math/Odd or Even Game/.idea/Odd or Even Game.iml diff --git a/Odd or Even Game/.idea/misc.xml b/Basic Math/Odd or Even Game/.idea/misc.xml similarity index 100% rename from Odd or Even Game/.idea/misc.xml rename to Basic Math/Odd or Even Game/.idea/misc.xml diff --git a/Odd or Even Game/.idea/modules.xml b/Basic Math/Odd or Even Game/.idea/modules.xml similarity index 100% rename from Odd or Even Game/.idea/modules.xml rename to Basic Math/Odd or Even Game/.idea/modules.xml diff --git a/Odd or Even Game/.idea/vcs.xml b/Basic Math/Odd or Even Game/.idea/vcs.xml similarity index 100% rename from Odd or Even Game/.idea/vcs.xml rename to Basic Math/Odd or Even Game/.idea/vcs.xml diff --git a/Odd or Even Game/.idea/workspace.xml b/Basic Math/Odd or Even Game/.idea/workspace.xml similarity index 100% rename from Odd or Even Game/.idea/workspace.xml rename to Basic Math/Odd or Even Game/.idea/workspace.xml diff --git a/Odd or Even Game/OddEvenGame.txt b/Basic Math/Odd or Even Game/OddEvenGame.txt similarity index 100% rename from Odd or Even Game/OddEvenGame.txt rename to Basic Math/Odd or Even Game/OddEvenGame.txt diff --git a/Odd or Even Game/oddEvenGame.py b/Basic Math/Odd or Even Game/oddEvenGame.py similarity index 100% rename from Odd or Even Game/oddEvenGame.py rename to Basic Math/Odd or Even Game/oddEvenGame.py diff --git a/PROXY/question.txt b/Basic Math/PROXY/question.txt similarity index 100% rename from PROXY/question.txt rename to Basic Math/PROXY/question.txt diff --git a/PROXY/solution.cpp b/Basic Math/PROXY/solution.cpp similarity index 100% rename from PROXY/solution.cpp rename to Basic Math/PROXY/solution.cpp diff --git a/Prime_gen/Prime Generator(prime_gen) b/Basic Math/Prime_gen/Prime Generator(prime_gen) similarity index 100% rename from Prime_gen/Prime Generator(prime_gen) rename to Basic Math/Prime_gen/Prime Generator(prime_gen) diff --git a/Prime_gen/prime_gen.cpp b/Basic Math/Prime_gen/prime_gen.cpp similarity index 100% rename from Prime_gen/prime_gen.cpp rename to Basic Math/Prime_gen/prime_gen.cpp diff --git a/Save the Prisoner!/question.txt b/Basic Math/Save the Prisoner!/question.txt similarity index 100% rename from Save the Prisoner!/question.txt rename to Basic Math/Save the Prisoner!/question.txt diff --git a/Save the Prisoner!/solution.cpp b/Basic Math/Save the Prisoner!/solution.cpp similarity index 100% rename from Save the Prisoner!/solution.cpp rename to Basic Math/Save the Prisoner!/solution.cpp diff --git a/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md b/Basic Math/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md similarity index 100% rename from Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md rename to Basic Math/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md diff --git a/Sherlock-and-the-beast/solution.cpp b/Basic Math/Sherlock-and-the-beast/solution.cpp similarity index 94% rename from Sherlock-and-the-beast/solution.cpp rename to Basic Math/Sherlock-and-the-beast/solution.cpp index 3e7dff3..166e378 100644 --- a/Sherlock-and-the-beast/solution.cpp +++ b/Basic Math/Sherlock-and-the-beast/solution.cpp @@ -1,66 +1,66 @@ -#include - -using namespace std; - - -// Complete the decentNumber function below. - -void decent(int digits) -{ - int flag=0; - - if(digits==4 || digits==7 || digits<3) - flag=0; - else if(digits==5) - { - flag=1; - cout<<"33333\n"; - - } - else if(digits%3 ==0) - { - flag=1; - //(no. of times, what needs to be printed) - cout<=8) - { - - int remain3,remain5,temp; - - temp=digits%3; - flag=1; - if(temp==1) - { - remain5=digits-10; - remain3=10; - } - else if(temp==2) - { - remain5=digits-5; - remain3=5; - } - - cout<>cases; - while(cases-->0) - { - cin>>input; - decent(input); - } - return 0; +#include + +using namespace std; + + +// Complete the decentNumber function below. + +void decent(int digits) +{ + int flag=0; + + if(digits==4 || digits==7 || digits<3) + flag=0; + else if(digits==5) + { + flag=1; + cout<<"33333\n"; + + } + else if(digits%3 ==0) + { + flag=1; + //(no. of times, what needs to be printed) + cout<=8) + { + + int remain3,remain5,temp; + + temp=digits%3; + flag=1; + if(temp==1) + { + remain5=digits-10; + remain3=10; + } + else if(temp==2) + { + remain5=digits-5; + remain3=5; + } + + cout<>cases; + while(cases-->0) + { + cin>>input; + decent(input); + } + return 0; } \ No newline at end of file diff --git a/The Additionator/The Additionator.txt b/Basic Math/The Additionator/The Additionator.txt similarity index 100% rename from The Additionator/The Additionator.txt rename to Basic Math/The Additionator/The Additionator.txt diff --git a/The Additionator/solution.java b/Basic Math/The Additionator/solution.java similarity index 100% rename from The Additionator/solution.java rename to Basic Math/The Additionator/solution.java diff --git a/The Prime Game/Problem_statement.txt b/Basic Math/The Prime Game/Problem_statement.txt similarity index 99% rename from The Prime Game/Problem_statement.txt rename to Basic Math/The Prime Game/Problem_statement.txt index 050d2b2..062ec10 100644 --- a/The Prime Game/Problem_statement.txt +++ b/Basic Math/The Prime Game/Problem_statement.txt @@ -1,9 +1,9 @@ -Manasa loves the nim game, in which there are n buckets, each having Ai balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she gets bored one day. So she wants to change the rules of the game. She loves prime numbers, so she makes a new rule: any player can only remove a prime number of balls from a bucket. But there are infinite number prime numbers. So to keep the game simple, a player can only remove x balls from a bucket if x belongs to the set - -S = {2, 3, 5, 7, 11, 13} - -The whole game can now be described as follows: - -There are buckets, and the bucket contains balls. A player can choose a bucket and remove balls from that bucket where belongs to . A player loses if there are no more available moves. - +Manasa loves the nim game, in which there are n buckets, each having Ai balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she gets bored one day. So she wants to change the rules of the game. She loves prime numbers, so she makes a new rule: any player can only remove a prime number of balls from a bucket. But there are infinite number prime numbers. So to keep the game simple, a player can only remove x balls from a bucket if x belongs to the set + +S = {2, 3, 5, 7, 11, 13} + +The whole game can now be described as follows: + +There are buckets, and the bucket contains balls. A player can choose a bucket and remove balls from that bucket where belongs to . A player loses if there are no more available moves. + Manasa plays the first move against Sandy. Who will win if both of them play optimally? \ No newline at end of file diff --git a/The Prime Game/Solution.py b/Basic Math/The Prime Game/Solution.py similarity index 96% rename from The Prime Game/Solution.py rename to Basic Math/The Prime Game/Solution.py index 7ec6413..4238403 100644 --- a/The Prime Game/Solution.py +++ b/Basic Math/The Prime Game/Solution.py @@ -1,12 +1,12 @@ -s = [0, 0, 1, 1, 2, 2, 3, 3, 4] -t = int(input()) -for ti in range(t): - n = int(input()) - a = [int(ai) for ai in input().strip().split(" ")] - ans = 0 - for i in range(n): - ans = ans^s[int(a[i]%len(s))] - if(ans>0): - print("Manasa") - else: - print("Sandy") +s = [0, 0, 1, 1, 2, 2, 3, 3, 4] +t = int(input()) +for ti in range(t): + n = int(input()) + a = [int(ai) for ai in input().strip().split(" ")] + ans = 0 + for i in range(n): + ans = ans^s[int(a[i]%len(s))] + if(ans>0): + print("Manasa") + else: + print("Sandy") diff --git a/When to take medicine/problem_statement.txt b/Basic Math/When to take medicine/problem_statement.txt similarity index 100% rename from When to take medicine/problem_statement.txt rename to Basic Math/When to take medicine/problem_statement.txt diff --git a/When to take medicine/when to take medicine_answer.txt b/Basic Math/When to take medicine/when to take medicine_answer.txt similarity index 100% rename from When to take medicine/when to take medicine_answer.txt rename to Basic Math/When to take medicine/when to take medicine_answer.txt diff --git a/find_factorial_of_a_number/find_factorial_of_a_number.txt b/Basic Math/find_factorial_of_a_number/find_factorial_of_a_number.txt similarity index 100% rename from find_factorial_of_a_number/find_factorial_of_a_number.txt rename to Basic Math/find_factorial_of_a_number/find_factorial_of_a_number.txt diff --git a/find_factorial_of_a_number/solution.cpp b/Basic Math/find_factorial_of_a_number/solution.cpp similarity index 100% rename from find_factorial_of_a_number/solution.cpp rename to Basic Math/find_factorial_of_a_number/solution.cpp diff --git a/project_euler problem12/Highly divisible triangular number.cpp b/Basic Math/project_euler problem12/Highly divisible triangular number.cpp similarity index 100% rename from project_euler problem12/Highly divisible triangular number.cpp rename to Basic Math/project_euler problem12/Highly divisible triangular number.cpp diff --git a/project_euler problem12/problem b/Basic Math/project_euler problem12/problem similarity index 100% rename from project_euler problem12/problem rename to Basic Math/project_euler problem12/problem diff --git a/CollatzConjecture/CollatzConjecture.txt b/Basic Program/CollatzConjecture/CollatzConjecture.txt similarity index 100% rename from CollatzConjecture/CollatzConjecture.txt rename to Basic Program/CollatzConjecture/CollatzConjecture.txt diff --git a/CollatzConjecture/solution.c b/Basic Program/CollatzConjecture/solution.c similarity index 95% rename from CollatzConjecture/solution.c rename to Basic Program/CollatzConjecture/solution.c index 600e64a..0f667da 100644 --- a/CollatzConjecture/solution.c +++ b/Basic Program/CollatzConjecture/solution.c @@ -1,23 +1,23 @@ -#include -#include - -int main(){ - long int N = 26; //CALCULATING FOR N = 26 - long int biggestValue = 0; - long int steps = 0; - - while(N != 1){ - if(N%2 == 0){ - N = N/2; - }else{ - N = N*3 + 1; - } - if(N>biggestValue){ - biggestValue = N; - } - steps++; - } - - printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); - +#include +#include + +int main(){ + long int N = 26; //CALCULATING FOR N = 26 + long int biggestValue = 0; + long int steps = 0; + + while(N != 1){ + if(N%2 == 0){ + N = N/2; + }else{ + N = N*3 + 1; + } + if(N>biggestValue){ + biggestValue = N; + } + steps++; + } + + printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); + } \ No newline at end of file diff --git a/EncoderProblem/Encoder.java b/Basic Program/EncoderProblem/Encoder.java similarity index 100% rename from EncoderProblem/Encoder.java rename to Basic Program/EncoderProblem/Encoder.java diff --git a/EncoderProblem/problem.txt b/Basic Program/EncoderProblem/problem.txt similarity index 100% rename from EncoderProblem/problem.txt rename to Basic Program/EncoderProblem/problem.txt diff --git a/Leap Year/instructions.txt b/Basic Program/Leap Year/instructions.txt similarity index 100% rename from Leap Year/instructions.txt rename to Basic Program/Leap Year/instructions.txt diff --git a/Leap Year/ruby_solution.rb b/Basic Program/Leap Year/ruby_solution.rb similarity index 100% rename from Leap Year/ruby_solution.rb rename to Basic Program/Leap Year/ruby_solution.rb diff --git a/Sleep_In/sleep_in.py b/Basic Program/Sleep_In/sleep_in.py similarity index 100% rename from Sleep_In/sleep_in.py rename to Basic Program/Sleep_In/sleep_in.py diff --git a/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt b/Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt similarity index 100% rename from how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt rename to Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt diff --git a/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py b/Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py similarity index 100% rename from how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py rename to Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py diff --git a/Aggressive Cows Spoj/problem statement.txt b/Binary Search/Aggressive Cows Spoj/problem statement.txt similarity index 100% rename from Aggressive Cows Spoj/problem statement.txt rename to Binary Search/Aggressive Cows Spoj/problem statement.txt diff --git a/Aggressive Cows Spoj/solution1.cpp b/Binary Search/Aggressive Cows Spoj/solution1.cpp similarity index 100% rename from Aggressive Cows Spoj/solution1.cpp rename to Binary Search/Aggressive Cows Spoj/solution1.cpp diff --git a/Aggressive Cows Spoj/solution2.cpp b/Binary Search/Aggressive Cows Spoj/solution2.cpp similarity index 100% rename from Aggressive Cows Spoj/solution2.cpp rename to Binary Search/Aggressive Cows Spoj/solution2.cpp diff --git a/binary_search/binary_search.txt b/Binary Search/binary_search/binary_search.txt similarity index 100% rename from binary_search/binary_search.txt rename to Binary Search/binary_search/binary_search.txt diff --git a/binary_search/bs.class b/Binary Search/binary_search/bs.class similarity index 100% rename from binary_search/bs.class rename to Binary Search/binary_search/bs.class diff --git a/binary_search/bs.ctxt b/Binary Search/binary_search/bs.ctxt similarity index 100% rename from binary_search/bs.ctxt rename to Binary Search/binary_search/bs.ctxt diff --git a/binary_search/bs.java b/Binary Search/binary_search/bs.java similarity index 100% rename from binary_search/bs.java rename to Binary Search/binary_search/bs.java diff --git a/binary_search/solution.cpp b/Binary Search/binary_search/solution.cpp similarity index 100% rename from binary_search/solution.cpp rename to Binary Search/binary_search/solution.cpp diff --git a/binary_search/solution.py b/Binary Search/binary_search/solution.py similarity index 100% rename from binary_search/solution.py rename to Binary Search/binary_search/solution.py diff --git a/ZOMCAV/ZOMCAV.txt b/Bitwise Operation/ZOMCAV/ZOMCAV.txt similarity index 100% rename from ZOMCAV/ZOMCAV.txt rename to Bitwise Operation/ZOMCAV/ZOMCAV.txt diff --git a/ZOMCAV/codechef.class b/Bitwise Operation/ZOMCAV/codechef.class similarity index 100% rename from ZOMCAV/codechef.class rename to Bitwise Operation/ZOMCAV/codechef.class diff --git a/ZOMCAV/codechef.ctxt b/Bitwise Operation/ZOMCAV/codechef.ctxt similarity index 100% rename from ZOMCAV/codechef.ctxt rename to Bitwise Operation/ZOMCAV/codechef.ctxt diff --git a/ZOMCAV/codechef.java b/Bitwise Operation/ZOMCAV/codechef.java similarity index 100% rename from ZOMCAV/codechef.java rename to Bitwise Operation/ZOMCAV/codechef.java diff --git a/0-1 Knapsack Problem/Question.txt b/Dynamic Programming/0-1 Knapsack Problem/Question.txt similarity index 100% rename from 0-1 Knapsack Problem/Question.txt rename to Dynamic Programming/0-1 Knapsack Problem/Question.txt diff --git a/0-1 Knapsack Problem/Solution.c b/Dynamic Programming/0-1 Knapsack Problem/Solution.c similarity index 100% rename from 0-1 Knapsack Problem/Solution.c rename to Dynamic Programming/0-1 Knapsack Problem/Solution.c diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py b/Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py similarity index 100% rename from Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py rename to Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt b/Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt similarity index 100% rename from Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt rename to Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt diff --git a/Bytelandian-gold-coins/instructions.txt b/Dynamic Programming/Bytelandian-gold-coins/instructions.txt similarity index 100% rename from Bytelandian-gold-coins/instructions.txt rename to Dynamic Programming/Bytelandian-gold-coins/instructions.txt diff --git a/Bytelandian-gold-coins/solution.cpp b/Dynamic Programming/Bytelandian-gold-coins/solution.cpp similarity index 100% rename from Bytelandian-gold-coins/solution.cpp rename to Dynamic Programming/Bytelandian-gold-coins/solution.cpp diff --git a/COINS/Question.txt b/Dynamic Programming/COINS/Question.txt similarity index 100% rename from COINS/Question.txt rename to Dynamic Programming/COINS/Question.txt diff --git a/COINS/Readme.md b/Dynamic Programming/COINS/Readme.md similarity index 100% rename from COINS/Readme.md rename to Dynamic Programming/COINS/Readme.md diff --git a/COINS/Solution.cpp b/Dynamic Programming/COINS/Solution.cpp similarity index 100% rename from COINS/Solution.cpp rename to Dynamic Programming/COINS/Solution.cpp diff --git a/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt b/Dynamic Programming/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt similarity index 100% rename from DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt rename to Dynamic Programming/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt diff --git a/DP- Min Steps to 1/minsteps.java b/Dynamic Programming/DP- Min Steps to 1/minsteps.java similarity index 100% rename from DP- Min Steps to 1/minsteps.java rename to Dynamic Programming/DP- Min Steps to 1/minsteps.java diff --git a/Magic-Spells-LCS/problem.txt b/Dynamic Programming/Magic-Spells-LCS/problem.txt similarity index 100% rename from Magic-Spells-LCS/problem.txt rename to Dynamic Programming/Magic-Spells-LCS/problem.txt diff --git a/Magic-Spells-LCS/solution.cpp b/Dynamic Programming/Magic-Spells-LCS/solution.cpp similarity index 100% rename from Magic-Spells-LCS/solution.cpp rename to Dynamic Programming/Magic-Spells-LCS/solution.cpp diff --git a/Max_Sum_Contiguous_Subarray/Question.txt b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Question.txt similarity index 100% rename from Max_Sum_Contiguous_Subarray/Question.txt rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Question.txt diff --git a/Max_Sum_Contiguous_Subarray/Readme.md b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Readme.md similarity index 100% rename from Max_Sum_Contiguous_Subarray/Readme.md rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Readme.md diff --git a/Max_Sum_Contiguous_Subarray/Solution.cpp b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Solution.cpp similarity index 100% rename from Max_Sum_Contiguous_Subarray/Solution.cpp rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Solution.cpp diff --git a/Maximize the Product/Maximize the product.txt b/Dynamic Programming/Maximize the Product/Maximize the product.txt similarity index 100% rename from Maximize the Product/Maximize the product.txt rename to Dynamic Programming/Maximize the Product/Maximize the product.txt diff --git a/Maximize the Product/solution.cpp b/Dynamic Programming/Maximize the Product/solution.cpp similarity index 100% rename from Maximize the Product/solution.cpp rename to Dynamic Programming/Maximize the Product/solution.cpp diff --git a/Maximum sum of digits/code.cpp b/Dynamic Programming/Maximum sum of digits/code.cpp similarity index 100% rename from Maximum sum of digits/code.cpp rename to Dynamic Programming/Maximum sum of digits/code.cpp diff --git a/Maximum sum of digits/problem_statement.txt b/Dynamic Programming/Maximum sum of digits/problem_statement.txt similarity index 100% rename from Maximum sum of digits/problem_statement.txt rename to Dynamic Programming/Maximum sum of digits/problem_statement.txt diff --git a/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem b/Dynamic Programming/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem similarity index 100% rename from Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem rename to Dynamic Programming/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem diff --git a/Maximum-Perimeter-Triangle/Solution.cpp b/Dynamic Programming/Maximum-Perimeter-Triangle/Solution.cpp similarity index 100% rename from Maximum-Perimeter-Triangle/Solution.cpp rename to Dynamic Programming/Maximum-Perimeter-Triangle/Solution.cpp diff --git a/Powerset/powerset.js b/Dynamic Programming/Powerset/powerset.js similarity index 100% rename from Powerset/powerset.js rename to Dynamic Programming/Powerset/powerset.js diff --git a/Powerset/question.txt b/Dynamic Programming/Powerset/question.txt similarity index 100% rename from Powerset/question.txt rename to Dynamic Programming/Powerset/question.txt diff --git a/Prime_subsequence/question.txt b/Dynamic Programming/Prime_subsequence/question.txt similarity index 100% rename from Prime_subsequence/question.txt rename to Dynamic Programming/Prime_subsequence/question.txt diff --git a/Prime_subsequence/solution.cpp b/Dynamic Programming/Prime_subsequence/solution.cpp similarity index 100% rename from Prime_subsequence/solution.cpp rename to Dynamic Programming/Prime_subsequence/solution.cpp diff --git a/ROCK/problem.txt b/Dynamic Programming/ROCK/problem.txt similarity index 100% rename from ROCK/problem.txt rename to Dynamic Programming/ROCK/problem.txt diff --git a/ROCK/rock.cpp b/Dynamic Programming/ROCK/rock.cpp similarity index 100% rename from ROCK/rock.cpp rename to Dynamic Programming/ROCK/rock.cpp diff --git a/Rod cutting problem/question.txt b/Dynamic Programming/Rod cutting problem/question.txt similarity index 100% rename from Rod cutting problem/question.txt rename to Dynamic Programming/Rod cutting problem/question.txt diff --git a/Rod cutting problem/solution.java b/Dynamic Programming/Rod cutting problem/solution.java similarity index 100% rename from Rod cutting problem/solution.java rename to Dynamic Programming/Rod cutting problem/solution.java diff --git a/The Mailbox Manufacturers Problem/mailbox-question.txt b/Dynamic Programming/The Mailbox Manufacturers Problem/mailbox-question.txt similarity index 100% rename from The Mailbox Manufacturers Problem/mailbox-question.txt rename to Dynamic Programming/The Mailbox Manufacturers Problem/mailbox-question.txt diff --git a/The Mailbox Manufacturers Problem/solution.cpp b/Dynamic Programming/The Mailbox Manufacturers Problem/solution.cpp similarity index 100% rename from The Mailbox Manufacturers Problem/solution.cpp rename to Dynamic Programming/The Mailbox Manufacturers Problem/solution.cpp diff --git a/Zero_Sum_SubArray/question.txt b/Dynamic Programming/Zero_Sum_SubArray/question.txt similarity index 100% rename from Zero_Sum_SubArray/question.txt rename to Dynamic Programming/Zero_Sum_SubArray/question.txt diff --git a/Zero_Sum_SubArray/solution.cpp b/Dynamic Programming/Zero_Sum_SubArray/solution.cpp similarity index 100% rename from Zero_Sum_SubArray/solution.cpp rename to Dynamic Programming/Zero_Sum_SubArray/solution.cpp diff --git a/alphacode/problem_statement.txt b/Dynamic Programming/alphacode/problem_statement.txt similarity index 100% rename from alphacode/problem_statement.txt rename to Dynamic Programming/alphacode/problem_statement.txt diff --git a/alphacode/solution.txt b/Dynamic Programming/alphacode/solution.txt similarity index 100% rename from alphacode/solution.txt rename to Dynamic Programming/alphacode/solution.txt diff --git a/Product_of_lengths_all_cycles_undirected_graph/question.txt b/Graph/Product_of_lengths_all_cycles_undirected_graph/question.txt similarity index 100% rename from Product_of_lengths_all_cycles_undirected_graph/question.txt rename to Graph/Product_of_lengths_all_cycles_undirected_graph/question.txt diff --git a/Product_of_lengths_all_cycles_undirected_graph/solution.cpp b/Graph/Product_of_lengths_all_cycles_undirected_graph/solution.cpp similarity index 100% rename from Product_of_lengths_all_cycles_undirected_graph/solution.cpp rename to Graph/Product_of_lengths_all_cycles_undirected_graph/solution.cpp diff --git a/The_Coin_Change_Problem/Problem_Statement.txt b/Greedy/The_Coin_Change_Problem/Problem_Statement.txt similarity index 100% rename from The_Coin_Change_Problem/Problem_Statement.txt rename to Greedy/The_Coin_Change_Problem/Problem_Statement.txt diff --git a/The_Coin_Change_Problem/Solution.java b/Greedy/The_Coin_Change_Problem/Solution.java similarity index 100% rename from The_Coin_Change_Problem/Solution.java rename to Greedy/The_Coin_Change_Problem/Solution.java diff --git a/Implement a Line Editor with a Linked List/Problem Statement.txt b/LinkedList/Implement a Line Editor with a Linked List/Problem Statement.txt similarity index 100% rename from Implement a Line Editor with a Linked List/Problem Statement.txt rename to LinkedList/Implement a Line Editor with a Linked List/Problem Statement.txt diff --git a/Implement a Line Editor with a Linked List/Solution.cpp b/LinkedList/Implement a Line Editor with a Linked List/Solution.cpp similarity index 100% rename from Implement a Line Editor with a Linked List/Solution.cpp rename to LinkedList/Implement a Line Editor with a Linked List/Solution.cpp diff --git a/AAL/Aditya And Ladders.txt b/Patterns/AAL/Aditya And Ladders.txt similarity index 100% rename from AAL/Aditya And Ladders.txt rename to Patterns/AAL/Aditya And Ladders.txt diff --git a/AAL/x.cpp b/Patterns/AAL/x.cpp similarity index 100% rename from AAL/x.cpp rename to Patterns/AAL/x.cpp diff --git a/PatternPrinting/README.md b/Patterns/PatternPrinting/README.md similarity index 100% rename from PatternPrinting/README.md rename to Patterns/PatternPrinting/README.md diff --git a/PatternPrinting/sum.java b/Patterns/PatternPrinting/sum.java similarity index 95% rename from PatternPrinting/sum.java rename to Patterns/PatternPrinting/sum.java index d211336..292e80b 100644 --- a/PatternPrinting/sum.java +++ b/Patterns/PatternPrinting/sum.java @@ -1,36 +1,36 @@ -class Sum{ - public void print(int arr[],int n) - { - int b[] = new int[arr.length-1]; - if(arr.length>1) - { - for(int i =0;i1) + { + for(int i =0;i -using namespace std; - -void copyArr(int from[], int si, int ei, int * to) { - // while (si <= ei) *to++ = *si++; - while (si <= ei) { - *to = from[si]; - ++si; - ++to; - } -} - - -void mergeSortedArray(int arr[], int si, int ei, int mid) { - - int tmp_A[100]; - int tmp_B[100]; - - copyArr(arr, si, mid, tmp_A); - copyArr(arr, mid + 1, ei, tmp_B); - - int i = 0; - int j = 0; - int k = si; - - //while a has elements and b has elements, I have to do something - int size_A = mid - si + 1; - int size_B = ei - (mid + 1) + 1; - - while (i < size_A && j < size_B) { - if (tmp_A[i] < tmp_B[j]) { - arr[k] = tmp_A[i]; - i++; - k++; - } - else { - arr[k++] = tmp_B[j++]; - } - } - - while (i < size_A) { - arr[k++] = tmp_A[i++]; - } - - while (j < size_B) arr[k++] = tmp_B[j++]; - - -} - - -void mergeSort(int arr[], int si, int ei) { - if (si >= ei) { - //no elements - return; - } - - int mid = (si + ei) / 2; - //sort the left part - mergeSort(arr, si, mid); - mergeSort(arr, mid + 1, ei); - - mergeSortedArray(arr, si, ei, mid); - -} - - -int main() { - int arr[100]; - int n; - cin >> n; - inputArr(arr, n); - - mergeSort(arr, 0, n - 1); - - printArr(arr, n); -} + +#include "../helper.h" +#include +using namespace std; + +void copyArr(int from[], int si, int ei, int * to) { + // while (si <= ei) *to++ = *si++; + while (si <= ei) { + *to = from[si]; + ++si; + ++to; + } +} + + +void mergeSortedArray(int arr[], int si, int ei, int mid) { + + int tmp_A[100]; + int tmp_B[100]; + + copyArr(arr, si, mid, tmp_A); + copyArr(arr, mid + 1, ei, tmp_B); + + int i = 0; + int j = 0; + int k = si; + + //while a has elements and b has elements, I have to do something + int size_A = mid - si + 1; + int size_B = ei - (mid + 1) + 1; + + while (i < size_A && j < size_B) { + if (tmp_A[i] < tmp_B[j]) { + arr[k] = tmp_A[i]; + i++; + k++; + } + else { + arr[k++] = tmp_B[j++]; + } + } + + while (i < size_A) { + arr[k++] = tmp_A[i++]; + } + + while (j < size_B) arr[k++] = tmp_B[j++]; + + +} + + +void mergeSort(int arr[], int si, int ei) { + if (si >= ei) { + //no elements + return; + } + + int mid = (si + ei) / 2; + //sort the left part + mergeSort(arr, si, mid); + mergeSort(arr, mid + 1, ei); + + mergeSortedArray(arr, si, ei, mid); + +} + + +int main() { + int arr[100]; + int n; + cin >> n; + inputArr(arr, n); + + mergeSort(arr, 0, n - 1); + + printArr(arr, n); +} diff --git a/Mersort_In_C++/mergesort.txt b/Sorting/Mersort_In_C++/mergesort.txt similarity index 100% rename from Mersort_In_C++/mergesort.txt rename to Sorting/Mersort_In_C++/mergesort.txt diff --git a/Quicksort-JS/question.txt b/Sorting/Quicksort-JS/question.txt similarity index 100% rename from Quicksort-JS/question.txt rename to Sorting/Quicksort-JS/question.txt diff --git a/Quicksort-JS/quickSort.js b/Sorting/Quicksort-JS/quickSort.js similarity index 100% rename from Quicksort-JS/quickSort.js rename to Sorting/Quicksort-JS/quickSort.js diff --git a/Quicksort-python/Question.txt b/Sorting/Quicksort-python/Question.txt similarity index 100% rename from Quicksort-python/Question.txt rename to Sorting/Quicksort-python/Question.txt diff --git a/Quicksort-python/algorithm.txt b/Sorting/Quicksort-python/algorithm.txt similarity index 100% rename from Quicksort-python/algorithm.txt rename to Sorting/Quicksort-python/algorithm.txt diff --git a/Quicksort-python/quickSort.py b/Sorting/Quicksort-python/quickSort.py old mode 100755 new mode 100644 similarity index 100% rename from Quicksort-python/quickSort.py rename to Sorting/Quicksort-python/quickSort.py diff --git a/bubble_sort_c/question.txt b/Sorting/bubble_sort_c/question.txt similarity index 100% rename from bubble_sort_c/question.txt rename to Sorting/bubble_sort_c/question.txt diff --git a/bubble_sort_c/solution/bubble_sort.c b/Sorting/bubble_sort_c/solution/bubble_sort.c similarity index 100% rename from bubble_sort_c/solution/bubble_sort.c rename to Sorting/bubble_sort_c/solution/bubble_sort.c diff --git a/bubble_sort_c/solution/bubble_sort.h b/Sorting/bubble_sort_c/solution/bubble_sort.h similarity index 100% rename from bubble_sort_c/solution/bubble_sort.h rename to Sorting/bubble_sort_c/solution/bubble_sort.h diff --git a/bubble_sort_c/solution/main.c b/Sorting/bubble_sort_c/solution/main.c similarity index 100% rename from bubble_sort_c/solution/main.c rename to Sorting/bubble_sort_c/solution/main.c diff --git a/bubble_sort_c/solution/print_array.c b/Sorting/bubble_sort_c/solution/print_array.c similarity index 100% rename from bubble_sort_c/solution/print_array.c rename to Sorting/bubble_sort_c/solution/print_array.c diff --git a/Generate Parentheses/Question.txt b/Stack/Generate Parentheses/Question.txt similarity index 100% rename from Generate Parentheses/Question.txt rename to Stack/Generate Parentheses/Question.txt diff --git a/Generate Parentheses/Solution b/Stack/Generate Parentheses/Solution old mode 100755 new mode 100644 similarity index 100% rename from Generate Parentheses/Solution rename to Stack/Generate Parentheses/Solution diff --git a/Generate Parentheses/Solution.cpp b/Stack/Generate Parentheses/Solution.cpp similarity index 100% rename from Generate Parentheses/Solution.cpp rename to Stack/Generate Parentheses/Solution.cpp diff --git a/Street parade/code.cpp b/Stack/Street parade/code.cpp similarity index 100% rename from Street parade/code.cpp rename to Stack/Street parade/code.cpp diff --git a/Street parade/problem_statement.txt b/Stack/Street parade/problem_statement.txt similarity index 100% rename from Street parade/problem_statement.txt rename to Stack/Street parade/problem_statement.txt diff --git a/AnagramChecking/anagram_checking.py b/String/AnagramChecking/anagram_checking.py old mode 100755 new mode 100644 similarity index 100% rename from AnagramChecking/anagram_checking.py rename to String/AnagramChecking/anagram_checking.py diff --git a/AnagramChecking/anagram_checking.txt b/String/AnagramChecking/anagram_checking.txt similarity index 100% rename from AnagramChecking/anagram_checking.txt rename to String/AnagramChecking/anagram_checking.txt diff --git a/Arrangement_of_Queue/Question.txt b/String/Arrangement_of_Queue/Question.txt similarity index 100% rename from Arrangement_of_Queue/Question.txt rename to String/Arrangement_of_Queue/Question.txt diff --git a/Arrangement_of_Queue/README.md b/String/Arrangement_of_Queue/README.md similarity index 100% rename from Arrangement_of_Queue/README.md rename to String/Arrangement_of_Queue/README.md diff --git a/Arrangement_of_Queue/Solution.py b/String/Arrangement_of_Queue/Solution.py similarity index 100% rename from Arrangement_of_Queue/Solution.py rename to String/Arrangement_of_Queue/Solution.py diff --git a/Cenit-Polar-Crypt/Issue.txt b/String/Cenit-Polar-Crypt/Issue.txt similarity index 100% rename from Cenit-Polar-Crypt/Issue.txt rename to String/Cenit-Polar-Crypt/Issue.txt diff --git a/Cenit-Polar-Crypt/Solution.js b/String/Cenit-Polar-Crypt/Solution.js similarity index 100% rename from Cenit-Polar-Crypt/Solution.js rename to String/Cenit-Polar-Crypt/Solution.js diff --git a/Check_String_Palindrome/Source1.cpp b/String/Check_String_Palindrome/Source1.cpp similarity index 100% rename from Check_String_Palindrome/Source1.cpp rename to String/Check_String_Palindrome/Source1.cpp diff --git a/Check_String_Palindrome/problem.txt b/String/Check_String_Palindrome/problem.txt similarity index 100% rename from Check_String_Palindrome/problem.txt rename to String/Check_String_Palindrome/problem.txt diff --git a/FANCY/problem.txt b/String/FANCY/problem.txt similarity index 100% rename from FANCY/problem.txt rename to String/FANCY/problem.txt diff --git a/FANCY/solution.py b/String/FANCY/solution.py similarity index 100% rename from FANCY/solution.py rename to String/FANCY/solution.py diff --git a/Isograms/isograms.py b/String/Isograms/isograms.py similarity index 100% rename from Isograms/isograms.py rename to String/Isograms/isograms.py diff --git a/Isograms/problem_statement.txt b/String/Isograms/problem_statement.txt similarity index 100% rename from Isograms/problem_statement.txt rename to String/Isograms/problem_statement.txt diff --git a/Palindrome/palindrome.c b/String/Palindrome/palindrome.c similarity index 100% rename from Palindrome/palindrome.c rename to String/Palindrome/palindrome.c diff --git a/Palindrome/question.txt b/String/Palindrome/question.txt similarity index 100% rename from Palindrome/question.txt rename to String/Palindrome/question.txt diff --git a/Python_Palindrome/PalindromeQues.txt b/String/Python_Palindrome/PalindromeQues.txt similarity index 100% rename from Python_Palindrome/PalindromeQues.txt rename to String/Python_Palindrome/PalindromeQues.txt diff --git a/Python_Palindrome/solution.py b/String/Python_Palindrome/solution.py similarity index 100% rename from Python_Palindrome/solution.py rename to String/Python_Palindrome/solution.py diff --git a/Reverse string in place/question.txt b/String/Reverse string in place/question.txt similarity index 100% rename from Reverse string in place/question.txt rename to String/Reverse string in place/question.txt diff --git a/Reverse string in place/solution.java b/String/Reverse string in place/solution.java similarity index 100% rename from Reverse string in place/solution.java rename to String/Reverse string in place/solution.java diff --git a/ReverseChars/ReverseChars.java b/String/ReverseChars/ReverseChars.java similarity index 95% rename from ReverseChars/ReverseChars.java rename to String/ReverseChars/ReverseChars.java index 75aa58d..bd0c68e 100644 --- a/ReverseChars/ReverseChars.java +++ b/String/ReverseChars/ReverseChars.java @@ -1,26 +1,26 @@ -class main { - - public static void main(String[] args){ - - System.out.println(reverseChars("These Chars will be in reverse")); - - } - - public static String reverseChars(String reverseIt) { - - int stringLength; - String itReversed; - - reverseIt = reverseIt; - - stringLength = reverseIt.length(); - itReversed = ""; - - for (int i = 1; i <= stringLength; i++){ - char backwardChars = reverseIt.charAt(stringLength - i); - - itReversed += backwardChars; - } - return itReversed; - } +class main { + + public static void main(String[] args){ + + System.out.println(reverseChars("These Chars will be in reverse")); + + } + + public static String reverseChars(String reverseIt) { + + int stringLength; + String itReversed; + + reverseIt = reverseIt; + + stringLength = reverseIt.length(); + itReversed = ""; + + for (int i = 1; i <= stringLength; i++){ + char backwardChars = reverseIt.charAt(stringLength - i); + + itReversed += backwardChars; + } + return itReversed; + } } \ No newline at end of file diff --git a/ReverseChars/problem.txt b/String/ReverseChars/problem.txt similarity index 100% rename from ReverseChars/problem.txt rename to String/ReverseChars/problem.txt diff --git a/SplitString/Question.txt b/String/SplitString/Question.txt similarity index 100% rename from SplitString/Question.txt rename to String/SplitString/Question.txt diff --git a/SplitString/Solution.cpp b/String/SplitString/Solution.cpp similarity index 100% rename from SplitString/Solution.cpp rename to String/SplitString/Solution.cpp diff --git a/String_Permutation/question.txt b/String/String_Permutation/question.txt similarity index 100% rename from String_Permutation/question.txt rename to String/String_Permutation/question.txt diff --git a/String_Permutation/solution.cpp b/String/String_Permutation/solution.cpp similarity index 100% rename from String_Permutation/solution.cpp rename to String/String_Permutation/solution.cpp diff --git a/StrongPassword/solution.py b/String/StrongPassword/solution.py similarity index 100% rename from StrongPassword/solution.py rename to String/StrongPassword/solution.py diff --git a/StrongPassword/strongpasswordqn.txt b/String/StrongPassword/strongpasswordqn.txt similarity index 100% rename from StrongPassword/strongpasswordqn.txt rename to String/StrongPassword/strongpasswordqn.txt diff --git a/Subsequences/question.txt b/String/Subsequences/question.txt similarity index 100% rename from Subsequences/question.txt rename to String/Subsequences/question.txt diff --git a/Subsequences/subsequences.cpp b/String/Subsequences/subsequences.cpp old mode 100755 new mode 100644 similarity index 94% rename from Subsequences/subsequences.cpp rename to String/Subsequences/subsequences.cpp index b445c4f..9c0ec8c --- a/Subsequences/subsequences.cpp +++ b/String/Subsequences/subsequences.cpp @@ -1,27 +1,27 @@ -//find all the sub sequences of a string -#include -using namespace std; -char output[100] = ""; - -void printSubSeq(char str[], int be, int idx) -{ - if (str[be] == '\0') - { - output[idx] = '\0'; - cout << output << endl; - return; - } - - printSubSeq(str, be + 1, idx); - output[idx] = str[be]; - printSubSeq(str, be + 1, idx + 1); -} - - -int main() { - char str[100]; - cin >> str; - - - printSubSeq(str, 0, 0); -} +//find all the sub sequences of a string +#include +using namespace std; +char output[100] = ""; + +void printSubSeq(char str[], int be, int idx) +{ + if (str[be] == '\0') + { + output[idx] = '\0'; + cout << output << endl; + return; + } + + printSubSeq(str, be + 1, idx); + output[idx] = str[be]; + printSubSeq(str, be + 1, idx + 1); +} + + +int main() { + char str[100]; + cin >> str; + + + printSubSeq(str, 0, 0); +} diff --git a/The Reversed World/Solution.cpp b/String/The Reversed World/Solution.cpp similarity index 100% rename from The Reversed World/Solution.cpp rename to String/The Reversed World/Solution.cpp diff --git a/The Reversed World/The Reversed World.txt b/String/The Reversed World/The Reversed World.txt similarity index 100% rename from The Reversed World/The Reversed World.txt rename to String/The Reversed World/The Reversed World.txt diff --git a/ToyObsession/problem.c b/String/ToyObsession/problem.c similarity index 100% rename from ToyObsession/problem.c rename to String/ToyObsession/problem.c diff --git a/ToyObsession/solution.c b/String/ToyObsession/solution.c similarity index 100% rename from ToyObsession/solution.c rename to String/ToyObsession/solution.c diff --git a/Word_Frequency/question.txt b/String/Word_Frequency/question.txt similarity index 100% rename from Word_Frequency/question.txt rename to String/Word_Frequency/question.txt diff --git a/Word_Frequency/solution.js b/String/Word_Frequency/solution.js similarity index 100% rename from Word_Frequency/solution.js rename to String/Word_Frequency/solution.js diff --git a/ginortS/Question.txt b/String/ginortS/Question.txt similarity index 100% rename from ginortS/Question.txt rename to String/ginortS/Question.txt diff --git a/ginortS/Solution.py b/String/ginortS/Solution.py similarity index 100% rename from ginortS/Solution.py rename to String/ginortS/Solution.py diff --git a/size-of-tree-C++/problem_statement.txt b/Tree/size-of-tree-C++/problem_statement.txt similarity index 100% rename from size-of-tree-C++/problem_statement.txt rename to Tree/size-of-tree-C++/problem_statement.txt diff --git a/size-of-tree-C++/sizeoftree.cpp b/Tree/size-of-tree-C++/sizeoftree.cpp similarity index 100% rename from size-of-tree-C++/sizeoftree.cpp rename to Tree/size-of-tree-C++/sizeoftree.cpp diff --git a/Acronym/instructions.txt b/Unknown/Acronym/instructions.txt similarity index 100% rename from Acronym/instructions.txt rename to Unknown/Acronym/instructions.txt diff --git a/Acronym/ruby_solution.rb b/Unknown/Acronym/ruby_solution.rb similarity index 100% rename from Acronym/ruby_solution.rb rename to Unknown/Acronym/ruby_solution.rb diff --git a/CONTON/QUESTION.txt b/Unknown/CONTON/QUESTION.txt similarity index 100% rename from CONTON/QUESTION.txt rename to Unknown/CONTON/QUESTION.txt diff --git a/CONTON/solution.c b/Unknown/CONTON/solution.c similarity index 100% rename from CONTON/solution.c rename to Unknown/CONTON/solution.c diff --git a/Chefdil/ans.cpp b/Unknown/Chefdil/ans.cpp similarity index 100% rename from Chefdil/ans.cpp rename to Unknown/Chefdil/ans.cpp diff --git a/Chefdil/ques.txt b/Unknown/Chefdil/ques.txt similarity index 100% rename from Chefdil/ques.txt rename to Unknown/Chefdil/ques.txt diff --git a/Chocolate_SPOJ/question.txt b/Unknown/Chocolate_SPOJ/question.txt similarity index 100% rename from Chocolate_SPOJ/question.txt rename to Unknown/Chocolate_SPOJ/question.txt diff --git a/Chocolate_SPOJ/solution.java b/Unknown/Chocolate_SPOJ/solution.java similarity index 100% rename from Chocolate_SPOJ/solution.java rename to Unknown/Chocolate_SPOJ/solution.java diff --git a/Fair Rations/Answer.cpp b/Unknown/Fair Rations/Answer.cpp similarity index 100% rename from Fair Rations/Answer.cpp rename to Unknown/Fair Rations/Answer.cpp diff --git a/Fair Rations/Problem Statement .txt b/Unknown/Fair Rations/Problem Statement .txt similarity index 100% rename from Fair Rations/Problem Statement .txt rename to Unknown/Fair Rations/Problem Statement .txt diff --git a/Industrial Nim/Industrial_Nim.cpp b/Unknown/Industrial Nim/Industrial_Nim.cpp similarity index 100% rename from Industrial Nim/Industrial_Nim.cpp rename to Unknown/Industrial Nim/Industrial_Nim.cpp diff --git a/Industrial Nim/Industrial_Nim.txt b/Unknown/Industrial Nim/Industrial_Nim.txt similarity index 100% rename from Industrial Nim/Industrial_Nim.txt rename to Unknown/Industrial Nim/Industrial_Nim.txt diff --git a/Necklace/solution.cpp b/Unknown/Necklace/solution.cpp similarity index 100% rename from Necklace/solution.cpp rename to Unknown/Necklace/solution.cpp diff --git a/Necklace/statement.pdf b/Unknown/Necklace/statement.pdf similarity index 100% rename from Necklace/statement.pdf rename to Unknown/Necklace/statement.pdf diff --git a/PINS/problem.txt b/Unknown/PINS/problem.txt similarity index 100% rename from PINS/problem.txt rename to Unknown/PINS/problem.txt diff --git a/PINS/solution.cpp b/Unknown/PINS/solution.cpp similarity index 100% rename from PINS/solution.cpp rename to Unknown/PINS/solution.cpp diff --git a/PolyMul/question.txt b/Unknown/PolyMul/question.txt similarity index 100% rename from PolyMul/question.txt rename to Unknown/PolyMul/question.txt diff --git a/PolyMul/solution.cpp b/Unknown/PolyMul/solution.cpp similarity index 100% rename from PolyMul/solution.cpp rename to Unknown/PolyMul/solution.cpp diff --git a/Strange_Food_Chain/question.txt b/Unknown/Strange_Food_Chain/question.txt similarity index 100% rename from Strange_Food_Chain/question.txt rename to Unknown/Strange_Food_Chain/question.txt diff --git a/Strange_Food_Chain/solution.cpp b/Unknown/Strange_Food_Chain/solution.cpp similarity index 100% rename from Strange_Food_Chain/solution.cpp rename to Unknown/Strange_Food_Chain/solution.cpp diff --git a/WATCHFB/Main.class b/Unknown/WATCHFB/Main.class similarity index 100% rename from WATCHFB/Main.class rename to Unknown/WATCHFB/Main.class diff --git a/WATCHFB/Main.ctxt b/Unknown/WATCHFB/Main.ctxt similarity index 100% rename from WATCHFB/Main.ctxt rename to Unknown/WATCHFB/Main.ctxt diff --git a/WATCHFB/Main.java b/Unknown/WATCHFB/Main.java similarity index 100% rename from WATCHFB/Main.java rename to Unknown/WATCHFB/Main.java diff --git a/WATCHFB/WATCHFB.txt b/Unknown/WATCHFB/WATCHFB.txt similarity index 100% rename from WATCHFB/WATCHFB.txt rename to Unknown/WATCHFB/WATCHFB.txt diff --git a/chusky_adventurer/problem_statement.txt b/Unknown/chusky_adventurer/problem_statement.txt similarity index 100% rename from chusky_adventurer/problem_statement.txt rename to Unknown/chusky_adventurer/problem_statement.txt diff --git a/chusky_adventurer/solution.cpp b/Unknown/chusky_adventurer/solution.cpp similarity index 100% rename from chusky_adventurer/solution.cpp rename to Unknown/chusky_adventurer/solution.cpp diff --git a/chusky_hunger/problem_statement.txt b/Unknown/chusky_hunger/problem_statement.txt similarity index 100% rename from chusky_hunger/problem_statement.txt rename to Unknown/chusky_hunger/problem_statement.txt diff --git a/chusky_hunger/solution.cpp b/Unknown/chusky_hunger/solution.cpp similarity index 100% rename from chusky_hunger/solution.cpp rename to Unknown/chusky_hunger/solution.cpp diff --git a/chusky_nightgame/problem_statement.txt b/Unknown/chusky_nightgame/problem_statement.txt similarity index 100% rename from chusky_nightgame/problem_statement.txt rename to Unknown/chusky_nightgame/problem_statement.txt diff --git a/chusky_nightgame/solution.cpp b/Unknown/chusky_nightgame/solution.cpp similarity index 100% rename from chusky_nightgame/solution.cpp rename to Unknown/chusky_nightgame/solution.cpp diff --git a/coin-piles/problem_statement.txt b/Unknown/coin-piles/problem_statement.txt similarity index 100% rename from coin-piles/problem_statement.txt rename to Unknown/coin-piles/problem_statement.txt diff --git a/coin-piles/solution.cpp b/Unknown/coin-piles/solution.cpp similarity index 100% rename from coin-piles/solution.cpp rename to Unknown/coin-piles/solution.cpp From aafa1356e8a5eba80dc338e98721f2049128d405 Mon Sep 17 00:00:00 2001 From: syk007 Date: Sat, 10 Oct 2020 20:32:23 +0530 Subject: [PATCH 36/47] Added A greedy problem: Cutting a Rod --- Greedy/Cutting_a_Rod/CuttingARod.java | 33 ++++++++++++++++++++++ Greedy/Cutting_a_Rod/Problem_Statement.txt | 8 ++++++ 2 files changed, 41 insertions(+) create mode 100644 Greedy/Cutting_a_Rod/CuttingARod.java create mode 100644 Greedy/Cutting_a_Rod/Problem_Statement.txt diff --git a/Greedy/Cutting_a_Rod/CuttingARod.java b/Greedy/Cutting_a_Rod/CuttingARod.java new file mode 100644 index 0000000..8a29c87 --- /dev/null +++ b/Greedy/Cutting_a_Rod/CuttingARod.java @@ -0,0 +1,33 @@ +/** + * Time Complexity : O(n^2) + * which is much better than the + * worst case time complexity of Naive Recursive implementation. + */ + +import java.util.*; +import java.io.*; + +class CuttingARod { + + public static int cutCutCut(int price[], int size) { + + int memory[] = new int[size+1]; + memory[0] = 0; + + for(int i=1; i<=size; i++){ + int maximum = Integer.MIN_VALUE; + for(int j=0; j Date: Mon, 12 Oct 2020 15:02:15 +0530 Subject: [PATCH 37/47] A simple question on 2D array --- .../Hourglass in Array/Hourglass in Array.txt | 59 +++++++++++++++++++ Array/Hourglass in Array/Solution.cpp | 58 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 Array/Hourglass in Array/Hourglass in Array.txt create mode 100644 Array/Hourglass in Array/Solution.cpp diff --git a/Array/Hourglass in Array/Hourglass in Array.txt b/Array/Hourglass in Array/Hourglass in Array.txt new file mode 100644 index 0000000..7360172 --- /dev/null +++ b/Array/Hourglass in Array/Hourglass in Array.txt @@ -0,0 +1,59 @@ +Given a 6x6 2D Array, arr: + +1 1 1 0 0 0 +0 1 0 0 0 0 +1 1 1 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: + +a b c + d +e f g + +There are 16 hourglasses in . An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. + +Example + +arr = +-9 -9 -9 1 1 1 + 0 -9 0 4 3 2 +-9 -9 -9 1 2 3 + 0 0 8 6 6 0 + 0 0 0 -2 0 0 + 0 0 1 2 4 0 + +The 16 hourglass sums are: + +-63, -34, -9, 12, +-10, 0, 28, 23, +-27, -11, -2, 10, + 9, 17, 25, 18 +The highest hourglass sum is 28 from the hourglass beginning at row 1, column 2: + +0 4 3 + 1 +8 6 6 +Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge. + +Function Description: + +Complete the function hourglassSum in the editor below. + +hourglassSum has the following parameter(s): + +int arr[6][6]: an array of integers +Returns + +int: the maximum hourglass sum + +Input Format +Each of the 6 lines of inputs arr[i] contains 6 space-separated integers arr[i][j]. + +Constraints +-9 <= arr[i][j] <= 9 +0 <= i,j <= 5 + +Output Format +Print the largest (maximum) hourglass sum found in arr. \ No newline at end of file diff --git a/Array/Hourglass in Array/Solution.cpp b/Array/Hourglass in Array/Solution.cpp new file mode 100644 index 0000000..9c54bb4 --- /dev/null +++ b/Array/Hourglass in Array/Solution.cpp @@ -0,0 +1,58 @@ +#include + +using namespace std; + +// Complete the hourglassSum function below. +int hourglassSum(vector> arr) { + + int sum[16]={0}; + int a[36]; + static int r=0,x=0; + + for(int i=0;i<6;i++){ + for(int j=0;j<6;j++,r++){ + a[r]=arr[i][j]; + } + } + + + for(int i=0;i<22;i++,x++){ + sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; + if(i==3 || i==9 || i==15) + i+=2; + cout << sum[x] << " "; + } + + int large = sum[0]; + + for(int i=1;i<16;i++){ + if(large> arr(6); + for (int i = 0; i < 6; i++) { + arr[i].resize(6); + + for (int j = 0; j < 6; j++) { + cin >> arr[i][j]; + } + + cin.ignore(numeric_limits::max(), '\n'); + } + + int result = hourglassSum(arr); + + fout << result << "\n"; + + fout.close(); + + return 0; +} \ No newline at end of file From 5a3e5a5cb1be8fa9a0659e9546023d145d4c7b92 Mon Sep 17 00:00:00 2001 From: zomsik Date: Tue, 13 Oct 2020 16:26:45 +0200 Subject: [PATCH 38/47] Added a question and answer to convert decimal numbers to binary numbers --- Stack/Binary numbers/Question.txt | 1 + Stack/Binary numbers/solution.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Stack/Binary numbers/Question.txt create mode 100644 Stack/Binary numbers/solution.cpp diff --git a/Stack/Binary numbers/Question.txt b/Stack/Binary numbers/Question.txt new file mode 100644 index 0000000..d540fa0 --- /dev/null +++ b/Stack/Binary numbers/Question.txt @@ -0,0 +1 @@ +The question is how to make binary numbers using a stack. \ No newline at end of file diff --git a/Stack/Binary numbers/solution.cpp b/Stack/Binary numbers/solution.cpp new file mode 100644 index 0000000..a388706 --- /dev/null +++ b/Stack/Binary numbers/solution.cpp @@ -0,0 +1,27 @@ +#include +#include +using namespace std; +int main() +{ + int a,b,l,c; + stack stos; + cout << "Number to change: "; + cin >> a; + l=a; + + while(a!=0) + { + b=a%2; + a=a/2; + stos.push(b); + } + cout << "Number " << l << " is equal to: "; + while(!stos.empty()) + { + cout << stos.top(); + stos.pop(); + } + cout << " in binary system."; + +return 0; +} From a7c5f9a88365d7814a0d70546fef55fe91a6472b Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:04:02 +0530 Subject: [PATCH 39/47] Add files via upload --- Hourglass in Array/Hourglass in Array.txt | 15 ++++++ Hourglass in Array/Solution.cpp | 58 +++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Hourglass in Array/Hourglass in Array.txt create mode 100644 Hourglass in Array/Solution.cpp diff --git a/Hourglass in Array/Hourglass in Array.txt b/Hourglass in Array/Hourglass in Array.txt new file mode 100644 index 0000000..7f1f8f8 --- /dev/null +++ b/Hourglass in Array/Hourglass in Array.txt @@ -0,0 +1,15 @@ +Given a 2D Array, arr: + +1 1 1 0 0 0 +0 1 0 0 0 0 +1 1 1 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: + +a b c + d +e f g + +There are 16 hourglasses in arr. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. \ No newline at end of file diff --git a/Hourglass in Array/Solution.cpp b/Hourglass in Array/Solution.cpp new file mode 100644 index 0000000..c1af692 --- /dev/null +++ b/Hourglass in Array/Solution.cpp @@ -0,0 +1,58 @@ +#include + +using namespace std; + +// Complete the hourglassSum function below. +int hourglassSum(vector> arr) { + + int sum[16]={0}; + int a[36]; + static int r=0,x=0; + + for(int i=0;i<6;i++){ + for(int j=0;j<6;j++,r++){ + a[r]=arr[i][j]; + } + } + + + for(int i=0;i<22;i++,x++){ + sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; + if(i==3 || i==9 || i==15) + i+=2; + cout << sum[x] << " "; + } + + int large = sum[0]; + + for(int i=1;i<16;i++){ + if(large> arr(6); + for (int i = 0; i < 6; i++) { + arr[i].resize(6); + + for (int j = 0; j < 6; j++) { + cin >> arr[i][j]; + } + + cin.ignore(numeric_limits::max(), '\n'); + } + + int result = hourglassSum(arr); + + fout << result << "\n"; + + fout.close(); + + return 0; +} \ No newline at end of file From 4489358f2054ad3ec7ef9b33cc26eaecb403033f Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:09:27 +0530 Subject: [PATCH 40/47] Delete Hourglass in Array.txt --- Hourglass in Array/Hourglass in Array.txt | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Hourglass in Array/Hourglass in Array.txt diff --git a/Hourglass in Array/Hourglass in Array.txt b/Hourglass in Array/Hourglass in Array.txt deleted file mode 100644 index 7f1f8f8..0000000 --- a/Hourglass in Array/Hourglass in Array.txt +++ /dev/null @@ -1,15 +0,0 @@ -Given a 2D Array, arr: - -1 1 1 0 0 0 -0 1 0 0 0 0 -1 1 1 0 0 0 -0 0 0 0 0 0 -0 0 0 0 0 0 -0 0 0 0 0 0 -An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: - -a b c - d -e f g - -There are 16 hourglasses in arr. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. \ No newline at end of file From c50e528a58abb242a7d3caf593fb5824c113410d Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:09:49 +0530 Subject: [PATCH 41/47] Delete Solution.cpp --- Hourglass in Array/Solution.cpp | 58 --------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 Hourglass in Array/Solution.cpp diff --git a/Hourglass in Array/Solution.cpp b/Hourglass in Array/Solution.cpp deleted file mode 100644 index c1af692..0000000 --- a/Hourglass in Array/Solution.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -using namespace std; - -// Complete the hourglassSum function below. -int hourglassSum(vector> arr) { - - int sum[16]={0}; - int a[36]; - static int r=0,x=0; - - for(int i=0;i<6;i++){ - for(int j=0;j<6;j++,r++){ - a[r]=arr[i][j]; - } - } - - - for(int i=0;i<22;i++,x++){ - sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; - if(i==3 || i==9 || i==15) - i+=2; - cout << sum[x] << " "; - } - - int large = sum[0]; - - for(int i=1;i<16;i++){ - if(large> arr(6); - for (int i = 0; i < 6; i++) { - arr[i].resize(6); - - for (int j = 0; j < 6; j++) { - cin >> arr[i][j]; - } - - cin.ignore(numeric_limits::max(), '\n'); - } - - int result = hourglassSum(arr); - - fout << result << "\n"; - - fout.close(); - - return 0; -} \ No newline at end of file From 2d1f4d2835675a4ba52606a4ab20b1487f23f8ca Mon Sep 17 00:00:00 2001 From: shagunarora Date: Tue, 13 Oct 2020 22:01:31 +0530 Subject: [PATCH 42/47] Generate Parenthesis --- .../Generate_Parenthesis.cpp | 31 +++++++++++++++++++ .../Generate_parenthesis/Question.txt | 7 +++++ 2 files changed, 38 insertions(+) create mode 100644 Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp create mode 100644 Backtracking/Generate_parenthesis/Question.txt diff --git a/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp b/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp new file mode 100644 index 0000000..0b6a580 --- /dev/null +++ b/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +void Generate_Parenthesis(int open, int close, vector &ans, string s) +{ + if (close == 0) + { + ans.push_back(s); + return; + } + if (open) + { + string temp = s; + temp += '('; + Generate_Parenthesis(open - 1, close, ans, temp); + } + if (close > open) + { + string temp = s; + temp += ')'; + Generate_Parenthesis(open, close - 1, ans, temp); + } +} +int main() +{ + int n; + cin >> n; + vector ans; + Generate_Parenthesis(n, n, ans, ""); + for (int i = 0; i < ans.size(); i++) + cout << ans[i] << endl; +} \ No newline at end of file diff --git a/Backtracking/Generate_parenthesis/Question.txt b/Backtracking/Generate_parenthesis/Question.txt new file mode 100644 index 0000000..9012c1d --- /dev/null +++ b/Backtracking/Generate_parenthesis/Question.txt @@ -0,0 +1,7 @@ +Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. + +Sample Input +n = 3 + +Sample Output +["((()))","(()())","(())()","()(())","()()()"] \ No newline at end of file From 30966ca85f1097b334a1893ce62fd7884bd8cc00 Mon Sep 17 00:00:00 2001 From: aroradhruv2308 Date: Tue, 13 Oct 2020 22:10:14 +0530 Subject: [PATCH 43/47] Added question-largest_comman_subsequence --- .../largest_comman_subsecuence.cpp | 35 +++++++++++++++++++ .../largest_comman_subsequece/question.txt | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp create mode 100644 Dynamic Programming/largest_comman_subsequece/question.txt diff --git a/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp b/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp new file mode 100644 index 0000000..f8996f7 --- /dev/null +++ b/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; +int solver(string s1,string s2,vector>&dp,int n,int m) +{ + if(s1.empty()||s2.empty()) + return 0; + if(dp[n][m] >= 0) + return dp[n][m]; + if(s1[0]==s2[0]) + { + int ans = 1 + solver(s1.substr(1),s2.substr(1),dp,n-1,m-1); + dp[n][m] = ans; + return ans; + } + int ans1 = solver(s1,s2.substr(1),dp,n,m-1); + int ans2 = solver(s1.substr(1),s2,dp,n-1,m); + dp[n][m] = max(ans1,ans2); + return max(ans1,ans2); +} +int lcs(string s1, string s2) +{ + int n = s1.length(),m=s2.length(); + vector>dp(n+1,vector(m+1,-1)); + int ans = solver( s1, s2, dp , s1.length(),s2.length()); + return ans; +} + +int main() +{ + string s1, s2; + cin >> s1 >> s2; + cout << lcs(s1, s2); +} diff --git a/Dynamic Programming/largest_comman_subsequece/question.txt b/Dynamic Programming/largest_comman_subsequece/question.txt new file mode 100644 index 0000000..5f6391b --- /dev/null +++ b/Dynamic Programming/largest_comman_subsequece/question.txt @@ -0,0 +1,3 @@ +LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. + + From 564bbefa9a282dda6f0bfe43eab01ce733bdf26a Mon Sep 17 00:00:00 2001 From: aakankshaa23 Date: Wed, 14 Oct 2020 12:58:34 +0530 Subject: [PATCH 44/47] added gold mine problem --- .../Gold mine problem/GoldMineProblem.txt | 7 +++ .../Gold mine problem/solution.cpp.txt | 61 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dynamic Programming/Gold mine problem/GoldMineProblem.txt create mode 100644 Dynamic Programming/Gold mine problem/solution.cpp.txt diff --git a/Dynamic Programming/Gold mine problem/GoldMineProblem.txt b/Dynamic Programming/Gold mine problem/GoldMineProblem.txt new file mode 100644 index 0000000..76506c3 --- /dev/null +++ b/Dynamic Programming/Gold mine problem/GoldMineProblem.txt @@ -0,0 +1,7 @@ +Gold Mine Problem + +Given a gold mine of n*m dimensions. + Each field in this mine contains a positive integer which is the amount of gold in tons. +Initially the miner is at first column but can be at any row. + He can move only (right->,right up /,right down\) that is from a given cell, the miner can move to the cell diagonally up towards the right or right or diagonally down towards the right. +Find out maximum amount of gold he can collect. \ No newline at end of file diff --git a/Dynamic Programming/Gold mine problem/solution.cpp.txt b/Dynamic Programming/Gold mine problem/solution.cpp.txt new file mode 100644 index 0000000..13394ba --- /dev/null +++ b/Dynamic Programming/Gold mine problem/solution.cpp.txt @@ -0,0 +1,61 @@ +// C++ program to solve Gold Mine problem +#include +using namespace std; + +const int MAX = 100; + +// Returns maximum amount of gold that can be collected +// when journey started from first column and moves +// allowed are right, right-up and right-down +int getMaxGold(int gold[][MAX], int m, int n) +{ + // Create a table for storing intermediate results + // and initialize all cells to 0. The first row of + // goldMineTable gives the maximum gold that the miner + // can collect when starts that row + int goldTable[m][n]; + memset(goldTable, 0, sizeof(goldTable)); + + for (int col=n-1; col>=0; col--) + { + for (int row=0; row) + int right = (col==n-1)? 0: goldTable[row][col+1]; + + // Gold collected on going to the cell to right up (/) + int right_up = (row==0 || col==n-1)? 0: + goldTable[row-1][col+1]; + + // Gold collected on going to the cell to right down (\) + int right_down = (row==m-1 || col==n-1)? 0: + goldTable[row+1][col+1]; + + // Max gold collected from taking either of the + // above 3 paths + goldTable[row][col] = gold[row][col] + + max(right, max(right_up, right_down)); + + } + } + + // The max amount of gold collected will be the max + // value in first column of all rows + int res = goldTable[0][0]; + for (int i=1; i Date: Fri, 23 Oct 2020 10:33:29 +0530 Subject: [PATCH 45/47] Add Rotate the Array Question --- Array/Rotate Array/Question.txt | 1 + Array/Rotate Array/solution.kt | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Array/Rotate Array/Question.txt create mode 100644 Array/Rotate Array/solution.kt diff --git a/Array/Rotate Array/Question.txt b/Array/Rotate Array/Question.txt new file mode 100644 index 0000000..2152d32 --- /dev/null +++ b/Array/Rotate Array/Question.txt @@ -0,0 +1 @@ +We have to rotate the elements of the given array k times to the right. \ No newline at end of file diff --git a/Array/Rotate Array/solution.kt b/Array/Rotate Array/solution.kt new file mode 100644 index 0000000..0d58479 --- /dev/null +++ b/Array/Rotate Array/solution.kt @@ -0,0 +1,23 @@ +internal class Solution { + fun rotate(nums:IntArray, k:Int) { + k = k % nums.size + val count = 0 + val start = 0 + while (count < nums.size) + { + val current = start + val prev = nums[start] + do + { + val next = (current + k) % nums.size + val temp = nums[next] + nums[next] = prev + prev = temp + current = next + count++ + } + while (start != current) + start++ + } + } +} \ No newline at end of file From bdbcb0d599949557bd88f023a591141c644b5b83 Mon Sep 17 00:00:00 2001 From: poojabasker Date: Fri, 30 Oct 2020 13:14:13 +0530 Subject: [PATCH 46/47] Added Numbers to Words in Basic Math --- .../Number to Words/number_to_words.CPP | 62 +++++++++++++++++++ .../Number to Words/problem_definition.txt | 4 ++ 2 files changed, 66 insertions(+) create mode 100644 Basic Math/Number to Words/number_to_words.CPP create mode 100644 Basic Math/Number to Words/problem_definition.txt diff --git a/Basic Math/Number to Words/number_to_words.CPP b/Basic Math/Number to Words/number_to_words.CPP new file mode 100644 index 0000000..94e3047 --- /dev/null +++ b/Basic Math/Number to Words/number_to_words.CPP @@ -0,0 +1,62 @@ +//Converts any number between 0-9999 (inclusive) to words +//till 4 digits only + +#include +#include + +void words(int n, int c, int r) +{ + if(n==0 && c==1) + { + cout<<"Zero"<=20 || n==10) + { + cout<<" "<=14) + cout<<" "<>n; + int n1=n; + int count=0, rev=0; + while(n1!=0) + { + rev=rev*10+(n1%10); + count++; + n1=n1/10; + } + words(n,count,rev); + getch(); +} \ No newline at end of file diff --git a/Basic Math/Number to Words/problem_definition.txt b/Basic Math/Number to Words/problem_definition.txt new file mode 100644 index 0000000..0e39580 --- /dev/null +++ b/Basic Math/Number to Words/problem_definition.txt @@ -0,0 +1,4 @@ +Write code to convert a given number into words. +For example, +if “1234” is given as input +output should be “one thousand two hundred thirty four”. \ No newline at end of file From 77a9cd899b2630139afcd4beebce0dbf35c0c156 Mon Sep 17 00:00:00 2001 From: SimonLariz <50644041+SimonLariz@users.noreply.github.com> Date: Sat, 31 Oct 2020 09:23:45 -0700 Subject: [PATCH 47/47] Codeforces Problem Addition Addition of A.Team problem from codeforces --- Basic Program/A. Team/A.Team.cpp | 24 ++++++++++++++++++++++ Basic Program/A. Team/A.Team.txt | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Basic Program/A. Team/A.Team.cpp create mode 100644 Basic Program/A. Team/A.Team.txt diff --git a/Basic Program/A. Team/A.Team.cpp b/Basic Program/A. Team/A.Team.cpp new file mode 100644 index 0000000..05dfbeb --- /dev/null +++ b/Basic Program/A. Team/A.Team.cpp @@ -0,0 +1,24 @@ +#include + +int main() +{ + //Creation of vars + int n, a, b, c, count = 0; + //Take in input for n lines + std::cin >> n; + //Loop for n + for (int i = 0; i < n; i++) + { + //Take in user input + std::cin >> a; + std::cin >> b; + std::cin >> c; + //If more than 2 are sure then they will do the problem + if (a + b + c >= 2) + //Increase problem count + count++; + } + //Return problem count + std::cout << count; + return 0; +} diff --git a/Basic Program/A. Team/A.Team.txt b/Basic Program/A. Team/A.Team.txt new file mode 100644 index 0000000..f7d38b4 --- /dev/null +++ b/Basic Program/A. Team/A.Team.txt @@ -0,0 +1,34 @@ +A. Team [https://codeforces.com/contest/231/problem/A] + + +One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. + +This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. + +Input +The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. + +Output +Print a single integer — the number of problems the friends will implement on the contest. + +Examples +INPUT +3 +1 1 0 +1 1 1 +1 0 0 +OUTPUT +2 + +INPUT +2 +1 0 0 +0 1 1 +OUTPUT +1 + +Note +In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. + +In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. +