├── .github └── ISSUE_TEMPLATE │ ├── custom.md │ └── new-problem.md ├── .gitignore ├── .vscode └── settings.json ├── Code ├── AlternateSplitLinkedList.md ├── ArmStrong.md ├── BalancedParanthesis.md ├── BinaryExponentiation.md ├── BinarySearch.md ├── BinaryToGrayCode.md ├── BubbleSort_recursive.md ├── CheckPrime.md ├── ChessboardAndNQueens.md ├── ConstructTheRectangle.md ├── Decimal to Binary Conversion.md ├── Decode String.md ├── Factorial.md ├── Factorial2.md ├── Fibonacci.md ├── FindTheTownJudge.md ├── First-Index-of-Number.md ├── GCD.md ├── GCD_LCM.md ├── InsertionSort.md ├── IntegerDivisionCalculator.md ├── LetterCombinationsofPhoneNumber.md ├── LongestCommonprefix.md ├── LongestPalindromicSubstring.md ├── Matrix_Multiplication.md ├── Max_Product_Subset.md ├── MaximumSubarray.md ├── MergeSort.md ├── N-queens.md ├── Palindrome.md ├── Permutation Sequence.md ├── Permutations.md ├── Playlist.md ├── Power-of-number.md ├── PowerOfThree.md ├── PowerOfTwo.md ├── Print all leaf nodes of a Binary Tree.md ├── Print_ALL_String_Subsequence.md ├── Product of 2 Numbers.md ├── QuickSort.md ├── QuickSortJava.md ├── RecursiveTernarySearch.md ├── ReverseDoublyLinkedList.md ├── ReverseInGroups.md ├── ReverseLinkedList.md ├── ReverseStack.md ├── ReverseTheArray.md ├── Rotated_Palindrome_String.md ├── Rotten_Oranges.md ├── SelectionSort.md ├── Shortest_path_in_maze.md ├── SimplifiedKnapsackProblem.md ├── Sortastack.md ├── SourceToDestination.md ├── StaticRangeSumQueries.md ├── StringCreation.md ├── Subsequences.md ├── Sum of Digits.md ├── SwapNodesInPairs.md ├── ThreeSum.md ├── Tower_of_hanoi.md ├── TowerofHanoi.md ├── TwoSum.md ├── UniqueBinarySearchTrees.md ├── add_digits.md ├── delete_kth_node_from_linkedList.md ├── diameter_of_tree.md ├── factorial recursion.md ├── factorial_recursive.md ├── googleDriveNestedFolderAccess.md ├── gridPaths.md ├── mergeTwoSortedLists.md ├── palindrome program.md ├── print-array-using-recursion.md ├── print_KPC.md ├── reversingarray.md ├── rotateimage.md ├── vector_comparator.md ├── wildcard.md └── winnerOfCircularGame.md ├── README.md ├── index.html ├── other ├── Bit operation │ ├── basicoperations │ ├── basicoperations.cpp │ ├── evenandOdd │ ├── evenandOdd.cpp │ ├── forLoop │ ├── forLoop.cpp │ ├── leftandRightshift │ ├── leftandRightshift.cpp │ ├── sum │ ├── sum.cpp │ └── tempCodeRunnerFile.cpp ├── Recursion │ ├── BinarySearch │ ├── BinarySearch.cpp │ ├── String Recursion │ │ ├── Palindrome │ │ ├── Palindrome.cpp │ │ ├── Subset │ │ ├── Subset.cpp │ │ ├── bubbleSort │ │ ├── bubbleSort.cpp │ │ ├── mergeSort │ │ ├── mergeSort.cpp │ │ ├── power │ │ ├── power.cpp │ │ ├── quickort │ │ ├── quickort.cpp │ │ ├── ratInaMaze.cpp │ │ ├── reverseString │ │ ├── reverseString.cpp │ │ └── tempCodeRunnerFile.cpp │ ├── SumofArray │ ├── SumofArray.cpp │ ├── binarySearchRecursion │ ├── binarySearchRecursion.cpp │ ├── factorial │ ├── factorial.cpp │ ├── linearSearch │ ├── linearSearch.cpp │ ├── numtoWord │ ├── numtoWord.cpp │ ├── powof2 │ ├── powof2.cpp │ ├── printCounting │ ├── printCounting.cpp │ ├── tempCodeRunnerFile.cpp │ ├── walkingExp │ └── walkingExp.cpp ├── STL │ ├── Algorithms │ │ ├── binary │ │ ├── binary.cpp │ │ └── tempCodeRunnerFile.cpp │ ├── Array │ ├── Array.cpp │ ├── List │ ├── List.cpp │ ├── deque │ ├── deque.cpp │ ├── map │ ├── map.cpp │ ├── priorityQueue │ ├── priorityQueue.cpp │ ├── queue │ ├── queue.cpp │ ├── set │ ├── set.cpp │ ├── stack │ ├── stack.cpp │ ├── tempCodeRunnerFile.cpp │ ├── vector │ └── vector.cpp └── pointers │ ├── 2DDynamicArray │ ├── 2DDynamicArray.cpp │ ├── Barish │ ├── Barish.cpp │ ├── doublePointer.cpp │ ├── doublepointer │ ├── functionsPointers │ ├── functionsPointers.cpp │ ├── heapMemory │ ├── heapMemory.cpp │ ├── macros │ ├── defaultArguments │ ├── defaultArguments.cpp │ ├── inLineFunctions │ ├── inLineFunctions.cpp │ ├── macros │ ├── macros.cpp │ └── tempCodeRunnerFile.cpp │ ├── p2 │ ├── p2.cpp │ ├── pointer │ ├── pointer.cpp │ ├── pointer2 │ ├── pointer2.cpp │ ├── pointerWithArray │ ├── pointerWithArray.cpp │ ├── refrences │ ├── refrences.cpp │ └── tempCodeRunnerFile.cpp ├── package-lock.json ├── package.json ├── server.js ├── static ├── RCHUB.png ├── code.png ├── js │ └── index.js ├── top.png └── top1.jpg └── vercel.json /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new-problem.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: New Problem 3 | about: Ask for problem is taken or written yet. 4 | title: NewProlemAsk 5 | labels: newproblem 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | 107 | *.class 108 | *.exe 109 | .vercel 110 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": false, 3 | } -------------------------------------------------------------------------------- /Code/AlternateSplitLinkedList.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ankit Raibole' 3 | Github: 'https://github.com/iota-008' 4 | WebSite: 'https://iota-008.github.io' 5 | Problem: 'Alternate splitting of linked list' 6 | Description: 'splitting the linked list such that each new list has alternate elements from original list' 7 | Language: 'C++' 8 | --- 9 | ```C++ 10 | 11 | /** 12 | Original linked List: 0 1 2 3 4 5 13 | Resultant Linked List 'a' : 4 2 0 14 | Resultant Linked List 'b' : 5 3 1 15 | */ 16 | 17 | #include 18 | using namespace std; 19 | 20 | 21 | struct Node { 22 | int data; 23 | struct Node* next; 24 | }; 25 | 26 | void push(Node** head, int new_data) 27 | { 28 | Node* new_node = new Node; 29 | new_node->data = new_data; 30 | new_node->next = (*head); 31 | (*head) = new_node; 32 | } 33 | 34 | void moveNode(Node* a, Node* b) 35 | { 36 | if (b == NULL || a == NULL) 37 | return; 38 | 39 | if (a->next != NULL) 40 | a->next = a->next->next; 41 | 42 | if (b->next != NULL) 43 | b->next = b->next->next; 44 | 45 | moveNode(a->next, b->next); 46 | } 47 | 48 | void alternateSplitLinkedList(Node* head, Node** aRef, 49 | Node** bRef) 50 | { 51 | Node* curr = head; 52 | *aRef = curr; 53 | *bRef = curr->next; 54 | moveNode(*aRef, *bRef); 55 | } 56 | 57 | void display(Node* head) 58 | { 59 | Node* curr = head; 60 | while (curr != NULL) { 61 | printf("%d ", curr->data); 62 | curr = curr->next; 63 | } 64 | } 65 | 66 | int main() 67 | { 68 | Node* head = NULL; 69 | Node *a = NULL, *b = NULL; 70 | 71 | int n; 72 | cout<<"Enter number of nodes to insert : "; 73 | cin>>n; 74 | 75 | for(int i=0; i>x; 79 | push(&head, x); 80 | } 81 | 82 | alternateSplitLinkedList(head, &a, &b); 83 | 84 | printf("a : "); 85 | display(a); 86 | printf("\nb : "); 87 | display(b); 88 | 89 | return 0; 90 | } 91 | ``` -------------------------------------------------------------------------------- /Code/ArmStrong.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Manas Vijaywargiya' 3 | Github: 'https://github.com/manasdevslopes' 4 | WebSite: '' 5 | Problem: 'Armstrong Numbers' 6 | Description: 'Recursive method for Armstrong Numbers in JS' 7 | Language: 'JavaScript' 8 | --- 9 | ``` 10 | function armstrong(n){ 11 | let number = new String(n) 12 | 13 | n = number.length 14 | let output = 0 15 | for(let i of number) 16 | output = output + parseInt(i)**n 17 | 18 | if (output == parseInt(number)) 19 | return("True" + "
") 20 | else 21 | return("False" + "
") 22 | } 23 | 24 | document.write(armstrong(153)) 25 | document.write(armstrong(120)) 26 | 27 | ``` 28 | 29 | 30 | -------------------------------------------------------------------------------- /Code/BalancedParanthesis.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ankit Rao' 3 | Github: 'https://github.com/DragonUncaged' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Print thee Balanced Paranthesis' 6 | Description: 'For The Given number n print all the valid paranthesis.' 7 | Explanation: ' ith can be ‘(‘ if the count of ‘(‘ till i’th is less than n and i’th character can be ‘)’ if the count of ‘(‘ is greater than the count of ‘)’ till index i. ' 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | /* 12 | Ex. 13 | Input: 14 | n = 4 15 | Output: 16 | (((()))) 17 | ((()())) 18 | ((())()) 19 | ((()))() 20 | (()(())) 21 | (()()()) 22 | (()())() 23 | (())(()) 24 | (())()() 25 | ()((())) 26 | ()(()()) 27 | ()(())() 28 | ()()(()) 29 | ()()()() 30 | 31 | Create a recursive function that accepts a string (s), count of opening brackets (o) and count of closing brackets (c) and the value of n. 32 | 33 | if the value of opening bracket and closing bracket is equal to n then print the string and return. 34 | 35 | If the count of opening bracket is greater than count of closing bracket then call the function recursively with the following parameters String s + “}”, count of opening bracket o, count of closing bracket c + 1, and n. 36 | 37 | If the count of opening bracket is less than n then call the function recursively with the following parameters String s + “{“, count of opening bracket o + 1, count of closing bracket c, and n. 38 | 39 | */ 40 | #include "bits/stdc++.h" 41 | using namespace std; 42 | 43 | 44 | void gen(int open, int close, int n, std::string out) 45 | { 46 | if (close == n) 47 | { 48 | std::cout << out << "\n"; 49 | return; 50 | } 51 | if (open < n) 52 | { 53 | gen(open + 1, close, n, out + "("); 54 | } 55 | if (close < open) 56 | { 57 | gen(open, close + 1, n, out + ")"); 58 | } 59 | } 60 | 61 | int main() 62 | { 63 | int n; 64 | cin >> n; 65 | gen(0, 0, n, ""); 66 | 67 | return 0; 68 | } 69 | 70 | ``` 71 | -------------------------------------------------------------------------------- /Code/BinaryExponentiation.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pranay Chauhan' 3 | Github: 'https://github.com/PranayChauhan2516' 4 | WebSite: '' 5 | Problem: 'Binary Exponentiation' 6 | Description: 'Calculating power in O(logn)' 7 | Language: 'Java' 8 | --- 9 | ```java 10 | 11 | public class BinaryExponentiation { 12 | 13 | public static void main(String args[]) { 14 | System.out.println(calculatePower(2, 30)); 15 | } 16 | 17 | // Function to calculate x^y 18 | // Time Complexity: O(logn) 19 | public static long calculatePower(long x, long y) { 20 | if (y == 0) return 1 L; 21 | long val = calculatePower(x, y / 2); 22 | val *= val; 23 | if (y % 2 == 1) val *= x; 24 | return val; 25 | } 26 | } 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /Code/BinarySearch.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Tanmay Kulkarni' 3 | Github: 'https://github.com/tanmayck1201' 4 | WebSite: 'https://tanmayck1201.github.io/' 5 | Problem: 'Binary Search' 6 | Description: 'To search & check if particular element is present in the list or not using binary search.' 7 | Explanation: 'Size of an array, Array, & key element is given by user & following algorithm will 8 | check if that element is present in arraylist or not & give its index accordingly! 9 | ' 10 | Language: 'C++' 11 | --- 12 | 13 | ```C++ 14 | #include 15 | using namespace std; 16 | 17 | class BinSearch 18 | { 19 | public: 20 | float *A; 21 | int size; 22 | int l; 23 | 24 | BinSearch(); 25 | void Display(); 26 | int RBinSearch(float A[], int l, int h, int key); 27 | }; 28 | 29 | // Default cons. to get array elements. 30 | BinSearch ::BinSearch() 31 | { 32 | int n; 33 | cout << "Enter size of an array: "; 34 | cin >> size; 35 | A = new float[size]; 36 | l = 0; 37 | 38 | cout << "Enter no. of elements to enter: "; 39 | cin >> n; 40 | 41 | cout << "Enter the elements: \n"; 42 | for (int i = 0; i < n; i++) 43 | { 44 | cin >> A[i]; 45 | } 46 | l = n; 47 | } 48 | 49 | // Recursive function to implement binary search! 50 | int BinSearch ::RBinSearch(float A[], int l, int h, int key) 51 | { 52 | while (l <= h) 53 | { 54 | int mid = (l + h) / 2; 55 | if (A[mid] == key) 56 | { 57 | return mid; 58 | } 59 | else if (key < A[mid]) 60 | { 61 | return RBinSearch(A, l, mid - 1, key); 62 | } 63 | else 64 | { 65 | return RBinSearch(A, mid + 1, h, key); 66 | } 67 | } 68 | // if key not found. 69 | return -1; 70 | } 71 | 72 | // Can display array elements. 73 | void BinSearch ::Display() 74 | { 75 | cout << "The array elements are: \n"; 76 | for (int i = 0; i < l; i++) 77 | { 78 | cout << A[i] << endl; 79 | } 80 | } 81 | 82 | // Main/Driver function 83 | int main() 84 | { 85 | int key; 86 | BinSearch BS; 87 | cout << "Enter element to be searched: "; 88 | cin >> key; 89 | cout << "The element is found at index: " << BS.RBinSearch(BS.A, 0, BS.l, key) << endl; 90 | //BS.Display(); 91 | 92 | return 0; 93 | } 94 | ``` 95 | -------------------------------------------------------------------------------- /Code/BinaryToGrayCode.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ankit Raibole' 3 | Github: 'https://github.com/iota-008' 4 | WebSite: 'https://iota-008.github.io' 5 | Problem: 'Binary to Gray code converter.' 6 | Description: 'Binary to Gray code converter.' 7 | Language: 'C++' 8 | --- 9 | ```C++ 10 | /** 11 | Binary : 0011 12 | Gray : 0010 13 | 14 | Binary : 01001 15 | Gray : 01101 16 | */ 17 | 18 | #include 19 | using namespace std; 20 | 21 | int binary_to_gray(int n) 22 | { 23 | if (!n) 24 | return 0; 25 | 26 | int a = n % 10; 27 | 28 | int b = (n / 10) % 10; 29 | 30 | if ((a && !b) || (!a && b)) 31 | return (1 + 10 * binary_to_gray(n / 10)); 32 | 33 | return (10 * binary_to_gray(n / 10)); 34 | } 35 | 36 | int main() 37 | { 38 | int binary_number; 39 | cout<<"Enter binary number to be converted : " 40 | cin>>binary_number; 41 | 42 | printf("%d", binary_to_gray(binary_number)); 43 | return 0; 44 | } 45 | ``` -------------------------------------------------------------------------------- /Code/BubbleSort_recursive.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'DragonUncaged' 3 | Github: 'https://github.com/DragonUncaged' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Sort the List Using Bubble Sort Recursively' 6 | Description: 'Given List Of the number Use the Bubble Sort Algorithm To Sort the Array Increasing Order ' 7 | Explanation: 'Same the Bubble Sort Algorithm But the Loop is being replaced By Recursion' 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | /* 12 | Ex. 13 | Input: 14 | 6 15 | 64 34 25 12 22 11 90 16 | Output: 17 | 11 12 22 25 34 64 90 18 | 19 | Base Case: If array size is 1, return. 20 | Do One Pass of normal Bubble Sort. This pass fixes last element of current subarray. 21 | Recur for all elements except last of current subarray. 22 | 23 | */ 24 | 25 | #include "bits/stdc++.h" 26 | using namespace std; 27 | 28 | #define vi vector 29 | #define PB push_back 30 | 31 | 32 | void bubbleSort(vi &a, int i, int n) 33 | { 34 | if (n == 1) 35 | return; 36 | 37 | if (i == n - 1) 38 | { 39 | loop(z, 0, a.size() - 1) cout << a[z] << " "; 40 | cout << "\n"; 41 | bubbleSort(a, 0, n - 1); 42 | return; 43 | } 44 | 45 | if (a[i] > a[i + 1]) 46 | swap(a[i], a[i + 1]); 47 | 48 | bubbleSort(a, i + 1, n); 49 | } 50 | 51 | signed main() 52 | { 53 | int T; 54 | cin >> T; 55 | vi arr; 56 | loop(i, 0, T - 1) 57 | { 58 | int x; 59 | cin >> x; 60 | arr.PB(x); 61 | } 62 | bubbleSort(arr, 0, T); 63 | logarr(arr, 0, arr.size() - 1); 64 | return 0; 65 | } 66 | 67 | ``` 68 | -------------------------------------------------------------------------------- /Code/CheckPrime.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Samuele Bella' 3 | Github: 'https://github.com/Novaenn' 4 | WebSite: '' 5 | Problem: 'Check Prime Number' 6 | Description: 'Checks if the inserted number is prime.' 7 | Explanation : We check for every factor from 2 to the number and if num % i is equal zero then i is a factor of num. If we cant find any factor the number will be prime. 8 | Language: 'python' 9 | --- 10 | ```python 11 | 12 | num = int(input("Enter a number: ")) 13 | 14 | # prime numbers are greater than 1 15 | if num > 1: 16 | # check for factors 17 | for i in range(2,num): 18 | if (num % i) == 0: 19 | print(num," is not a prime number") 20 | print(i," times ",num//i," is ",num) 21 | break 22 | else: 23 | print(num," is a prime number") 24 | 25 | else: 26 | print(num," is not a prime number") 27 | -------------------------------------------------------------------------------- /Code/ChessboardAndNQueens.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pranay Chauhan' 3 | Github: 'https://github.com/PranayChauhan2516' 4 | WebSite: '' 5 | Problem: 'Chessboard and Queens' 6 | Description: 'Place 8 queens such that no two queens attack each other.' 7 | Language: 'Java' 8 | --- 9 | ```java 10 | 11 | import java.io.OutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.PrintWriter; 15 | import java.util.InputMismatchException; 16 | import java.io.IOException; 17 | import java.io.InputStream; 18 | 19 | /** 20 | * Built using CHelper plug-in 21 | * Actual solution is at the top 22 | * 23 | * @author Pranay2516 24 | */ 25 | public class Main { 26 | public static void main(String[] args) { 27 | InputStream inputStream = System.in; 28 | OutputStream outputStream = System.out; 29 | FastReader in = new FastReader(inputStream); 30 | PrintWriter out = new PrintWriter(outputStream); 31 | ChessboardAndQueens solver = new ChessboardAndQueens(); 32 | solver.solve(1, in, out); 33 | out.close(); 34 | } 35 | 36 | static class ChessboardAndQueens { 37 | boolean[][] grid = new boolean[8][8]; 38 | boolean[] col = new boolean[16]; 39 | boolean[] diag = new boolean[16]; 40 | boolean[] diag2 = new boolean[16]; 41 | int ways = 0; 42 | 43 | public void solve(int testNumber, FastReader in, PrintWriter out) { 44 | for (int i = 0; i < 8; ++i) { 45 | char[] c = in.next().toCharArray(); 46 | for (int j = 0; j < 8; ++j) { 47 | grid[i][j] = c[j] == '*'; 48 | } 49 | } 50 | go(0); 51 | out.println(ways); 52 | } 53 | 54 | void go(int r) { 55 | if (r == 8) { 56 | ways++; 57 | return; 58 | } 59 | for (int i = 0; i < 8; ++i) { 60 | if (col[i] || diag[r + i] || diag2[r - i + 7] || grid[r][i]) { 61 | continue; 62 | } 63 | col[i] = diag[r + i] = diag2[r - i + 7] = true; 64 | go(r + 1); 65 | col[i] = diag[r + i] = diag2[r - i + 7] = false; 66 | } 67 | } 68 | 69 | } 70 | 71 | static class FastReader { 72 | private InputStream stream; 73 | private byte[] buf = new byte[1024]; 74 | private int curChar; 75 | private int numChars; 76 | private FastReader.SpaceCharFilter filter; 77 | 78 | public FastReader(InputStream stream) { 79 | this.stream = stream; 80 | } 81 | 82 | public int read() { 83 | if (numChars == -1) throw new InputMismatchException(); 84 | if (curChar >= numChars) { 85 | curChar = 0; 86 | try { 87 | numChars = stream.read(buf); 88 | } catch (IOException e) { 89 | throw new InputMismatchException(); 90 | } 91 | if (numChars <= 0) return -1; 92 | } 93 | return buf[curChar++]; 94 | } 95 | 96 | public String next() { 97 | int c = read(); 98 | while (isSpaceChar(c)) c = read(); 99 | StringBuilder res = new StringBuilder(); 100 | do { 101 | res.appendCodePoint(c); 102 | c = read(); 103 | } while (!isSpaceChar(c)); 104 | return res.toString(); 105 | } 106 | 107 | public boolean isSpaceChar(int c) { 108 | if (filter != null) return filter.isSpaceChar(c); 109 | return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; 110 | } 111 | 112 | public interface SpaceCharFilter { 113 | public boolean isSpaceChar(int ch); 114 | 115 | } 116 | 117 | } 118 | } 119 | 120 | 121 | ``` 122 | -------------------------------------------------------------------------------- /Code/ConstructTheRectangle.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Sujata Choudhary' 3 | Github: 'https://github.com/sujatachoudhary598' 4 | WebSite: '' 5 | Problem: 'Construct a Rectangle' 6 | Description: 'A web developer needs to know how to design a web page size. So, given a specific rectangular web page area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 7 | 8 | 1. The area of the rectangular web page you designed must equal to the given target area. 9 | 2. The width W should not be larger than the length L, which means L >= W. 10 | 3. The difference between length L and width W should be as small as possible. 11 | 12 | Return an array [L, W] where L and W are the length and width of the web page you designed in sequence.' 13 | Language: 'Java' 14 | --- 15 | 16 | ```java 17 | public int[] constructRectangle(int area) { 18 | int sqrt = (int)Math.pow(area,0.5); 19 | if(sqrt*sqrt==area){ 20 | return new int[]{sqrt,sqrt}; 21 | } 22 | int[] ans=new int[2]; 23 | return rectangle(ans,area,sqrt); 24 | } 25 | int[] rectangle(int[] ans,int area, int sqrt){ 26 | if(sqrt<1){ 27 | return ans; 28 | } 29 | if(area%sqrt==0){ 30 | ans[1]=sqrt; 31 | ans[0]=area/sqrt; 32 | return ans; 33 | } 34 | return rectangle(ans,area,sqrt-1); 35 | } 36 | 37 | ``` 38 | -------------------------------------------------------------------------------- /Code/Decimal to Binary Conversion.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Krupal Patel' 3 | Github: 'https://github.com/iamkp1010' 4 | WebSite: '' 5 | Problem: 'Decimal to Binary using recursion' 6 | Description: 'Given Decimal number, convert it to binary.' 7 | Language: 'C++' 8 | --- 9 | 10 | ```C++ 11 | #include 12 | using namespace std; 13 | 14 | int find(int decimal_number) 15 | { 16 | if (decimal_number == 0) 17 | return 0; 18 | else 19 | return (decimal_number % 2 + 10 * find(decimal_number / 2)); 20 | } 21 | 22 | int main() 23 | { 24 | int decimal_number = 10; 25 | cout << find(decimal_number); 26 | return 0; 27 | } 28 | ``` -------------------------------------------------------------------------------- /Code/Decode String.md: -------------------------------------------------------------------------------- 1 | // Contributed by: 2 | Name: Abhijai Rajawat 3 | University: VIT, Vellore 4 | Github: www.github.com/Severus25 5 | Description: Given an encoded string, return its decoded string. 6 | Language used: C++ 7 | 8 | // Problem Solution: 9 | class Solution { 10 | public: 11 | string decodeString(const string& s, int& i) { 12 | string res; 13 | while (i < s.length() && s[i] != ']') { 14 | if (!isdigit(s[i])) 15 | res += s[i++]; 16 | else { 17 | int n = 0; 18 | while (i < s.length() && isdigit(s[i])) 19 | n = n * 10 + s[i++] - '0'; 20 | i++; 21 | string t = decodeString(s, i); 22 | i++; 23 | while (n-- > 0) 24 | res += t; 25 | } 26 | } 27 | return res; 28 | } 29 | string decodeString(string s) { 30 | int i = 0; 31 | return decodeString(s, i); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Code/Factorial.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'shelendravashishtha2 (Shelendra Vashishtha)r' 3 | Github: 'https://github.com/shelendravashishtha2' 4 | WebSite: 'https://shelendravashishtha2.github.io/portfolio/' 5 | Problem: 'Factorial of a Number' 6 | Description: 'Find the Factorial of a given Number. ' 7 | Explanation: 'Any Factorial number is a multiplication of numbers from 1 till that number.' 8 | Language: 'java' 9 | --- 10 | 11 | ```java 12 | import java.util.*; 13 | 14 | public class Factorial { 15 | public static long fact(int n) { 16 | if (n == 1) { 17 | return 1; 18 | } 19 | return n * fact(n - 1); 20 | } 21 | 22 | public static void main(String[] args) { 23 | Scanner s = new Scanner(System.in); 24 | System.out.println(fact(s.nextInt())); 25 | } 26 | } 27 | ``` -------------------------------------------------------------------------------- /Code/Factorial2.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Kanailal Manna' 3 | Github: 'https://github.com/KanailalManna' 4 | Problem: 'Nth Factorial Number' 5 | Description: 'Find the Nth Factorial Number.' 6 | Language: 'java' 7 | --- 8 | 9 | ```java 10 | import java.util.*; 11 | class Factorial{ 12 | public static void main(String args[]){ 13 | Scanner sc = new Scanner(System.in); 14 | int i,fact=1; 15 | System.out.println("Enter a number to calculate it's Factorial value"); 16 | int number = sc.nextInt(); 17 | for(i=1;i<=number;i++){ 18 | fact=fact*i; 19 | } 20 | System.out.println("Factorial of "+number+" is: "+fact); 21 | } 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /Code/Fibonacci.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Abha Barge' 3 | Github: 'https://github.com/AbhaBarge' 4 | WebSite: '' 5 | Problem: 'Fibonacci series with n members' 6 | Description: 'User inputs the number of required members, the series is printed as output, using recursion' 7 | Language: 'python' 8 | --- 9 | ```python 10 | def fibonacci(n, num, val=0, prev=0): 11 | ''' 12 | In the fibonacci series, the next member is the sum of the current member and its previous member" 13 | ''' 14 | if(n==num): 15 | print(0, end=" ") 16 | fibonacci(n-1,num,0, 1) 17 | 18 | elif(n==1): 19 | print(val + prev) 20 | 21 | else: 22 | curr = val + prev 23 | print(curr, end=" ") 24 | fibonacci(n-1,num, curr, val) 25 | 26 | fibonacci(23,23) 27 | 28 | ''' 29 | Gives output as : 30 | 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 31 | ''' 32 | ``` -------------------------------------------------------------------------------- /Code/FindTheTownJudge.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Jaydeep Pipaliya' 3 | Github: 'https://github.com/jaydeep-pipaliya' 4 | WebSite: 'https://leetcode.com/problems/find-the-town-judge' 5 | Problem: 'Find the Town Judge' 6 | Description: 'Calculating in O(2n)' 7 | Language: 'C++' 8 | --- 9 | ```C++ 10 | 11 | class Solution { 12 | public: 13 | int findJudge(int N, vector>& trust) { 14 | 15 | 16 | //1st value of pair denotes how many he trusts 17 | //2nd value of pair denotes how many trusts him 18 | vector> arr(N+1,{0,0}); 19 | for(int i=0;i= 0 && arr[j] > last) 38 | { 39 | arr[j+1] = arr[j]; 40 | j--; 41 | } 42 | arr[j+1] = last; 43 | } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /Code/IntegerDivisionCalculator.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'AlexMoonP' 3 | Github: 'https://github.com/AlexLunaP' 4 | WebSite: '' 5 | Problem: 'Calculate the division between two integers.' 6 | Description: 'This program uses recursion to calculate the division between two integers.' 7 | Language: 'C' 8 | --- 9 | ```C 10 | #include 11 | 12 | 13 | //Integer division calculator 14 | int integerDivision(int dividend, int divisor, int count){ 15 | if(dividend ans; 27 | 28 | map dict; 29 | 30 | void recurse(string formed,string digits) 31 | { 32 | 33 | if(digits.length() == 0) 34 | { 35 | ans.push_back(formed); 36 | } 37 | string corresponds = dict[digits[0]]; 38 | for(int i = 0;i letterCombinations(string digits) { 48 | ans.clear(); 49 | 50 | if(digits.length()==0) return ans; 51 | dict['2'] = "abc"; 52 | dict['3'] = "def"; 53 | dict['4'] = "ghi"; 54 | dict['5'] = "jkl"; 55 | dict['6'] = "mno"; 56 | dict['7'] = "pqrs"; 57 | dict['8'] = "tuv"; 58 | dict['9'] = "wxyz"; 59 | recurse("",digits); 60 | return ans; 61 | } 62 | }; 63 | ``` -------------------------------------------------------------------------------- /Code/LongestCommonprefix.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Jaydeep pipaliya' 3 | Github: 'https://github.com/jaydeep-pipaliya' 4 | WebSite: '' 5 | Problem: 'Longest Common Prefix' 6 | Description: 'Find Longest common prefix' 7 | Explanation : After sorting we compare first and last string and from that we make a answer string. 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | 12 | class Solution { 13 | public: 14 | string longestCommonPrefix(vector& strs) { 15 | int n = strs.size(); 16 | 17 | // Sort the vector 18 | sort(strs.begin(), strs.end()); 19 | string ans = ""; // for storing answer 20 | 21 | string a = strs[0]; // after sorting first element 22 | string b = strs[n-1]; // after sorting last element 23 | 24 | // We can compare for first and last , since they are sorted 25 | // i < a.length() ==> common prefix we can select least word 26 | for(int i = 0; i < a.length(); i++){ 27 | if(a[i] == b[i]){ 28 | // If same add in answer 29 | ans += a[i]; 30 | }else{ 31 | break; 32 | } 33 | } 34 | return ans; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Code/LongestPalindromicSubstring.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pranay Chauhan' 3 | Github: 'https://github.com/PranayChauhan2516' 4 | WebSite: '' 5 | Problem: 'Longest Palindromic Substring' 6 | Description: 'TC: O(n^2)' 7 | Language: 'Java' 8 | --- 9 | 10 | ```java 11 | 12 | public class LongestPalindromicSubstring { 13 | public static int maxLen, start; 14 | 15 | public static void main(String args[]) { 16 | System.out.println("Longest Palindromic Substring of 'babad' is " + longestPalindrome("babad")); 17 | } 18 | 19 | public static String longestPalindrome(String s) { 20 | if(s.length()<2) return s; 21 | for(int i=0;i=0 && r 12 | 13 | const int MAX = 100; 14 | 15 | void multiplyMatrixRec(int row1, int col1, int A[][MAX], 16 | int row2, int col2, int B[][MAX], 17 | int C[][MAX]) 18 | { 19 | // i and j are used to know current cell of 20 | // result matrix C[][]. k is used to know 21 | // current column number of A[][] and row 22 | // number of B[][] to be multiplied 23 | static int i = 0, j = 0, k = 0; 24 | 25 | // If all rows traversed. 26 | if (i >= row1) 27 | return; 28 | 29 | // If i < row1 30 | if (j < col2) 31 | { 32 | if (k < col1) 33 | { 34 | C[i][j] += A[i][k] * B[k][j]; 35 | k++; 36 | 37 | multiplyMatrixRec(row1, col1, A, row2, col2, 38 | B, C); 39 | } 40 | 41 | k = 0; 42 | j++; 43 | multiplyMatrixRec(row1, col1, A, row2, col2, B, C); 44 | } 45 | 46 | j = 0; 47 | i++; 48 | multiplyMatrixRec(row1, col1, A, row2, col2, B, C); 49 | } 50 | 51 | // Function to multiply two matrices A[][] and B[][] 52 | 53 | void multiplyMatrix(int row1, int col1, int A[][MAX], 54 | int row2, int col2, int B[][MAX]) 55 | { 56 | if (row2 != col1) 57 | { 58 | printf("Not Possible\n"); 59 | return; 60 | } 61 | 62 | int C[MAX][MAX] = {0}; 63 | 64 | multiplyMatrixRec(row1, col1, A, row2, col2, B, C); 65 | 66 | // Printing the result 67 | 68 | for (int i = 0; i < row1; i++) 69 | { 70 | for (int j = 0; j < col2; j++) 71 | printf("%d ", C[i][j]); 72 | 73 | printf("\n"); 74 | } 75 | } 76 | 77 | // Driven Program 78 | 79 | int main() 80 | { 81 | int A[][MAX] = { {1, 2, 3}, 82 | {4, 5, 6}, 83 | {7, 8, 9}}; 84 | 85 | int B[][MAX] = { {1, 2, 3}, 86 | {4, 5, 6}, 87 | {7, 8, 9} }; 88 | 89 | int row1 = 3, col1 = 3, row2 = 3, col2 = 3; 90 | multiplyMatrix(row1, col1, A, row2, col2, B); 91 | 92 | return 0; 93 | } 94 | ``` 95 | -------------------------------------------------------------------------------- /Code/Max_Product_Subset.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Plavani Sahoo' 3 | Github: 'https://github.com/plavani0208 ' 4 | Problem: 'Maximum Product Subset in an array' 5 | Description: 'C++ brute force solution for the problem' 6 | Language: 'C++' 7 | --- 8 | ``` C++ 9 | 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | // Function to generate the product of all elements in a given set 16 | // and update maximum product found so far 17 | 18 | void findMaxProduct(vector const &set, int &maximum) 19 | { 20 | int product = 1; 21 | 22 | for (int j: set) { 23 | product = product * j; 24 | } 25 | 26 | // if the set is not empty, then update the product 27 | 28 | if (set.size()) { 29 | maximum = max (maximum, product); 30 | } 31 | } 32 | 33 | // Function to generate a power set of a given set `S` 34 | 35 | void findPowerSet(vector const &S, vector &set, int n, int &maximum) 36 | { 37 | // if we have considered all elements, we have generated a subset 38 | if (n == 0) 39 | { 40 | // compute its product of elements and update the maximum product 41 | // found so far 42 | findMaxProduct(set, maximum); 43 | return; 44 | } 45 | 46 | // consider the n'th element 47 | 48 | set.push_back(S[n - 1]); 49 | findPowerSet(S, set, n - 1, maximum); 50 | 51 | set.pop_back(); 52 | 53 | // or don't consider the n'th element 54 | 55 | findPowerSet(S, set, n - 1, maximum); 56 | } 57 | 58 | int main() 59 | { 60 | vector S = { -6, 4, -5, 8, -10, 0, 8 }; 61 | int n = S.size(); 62 | 63 | vector set; 64 | int maximum = INT_MIN; 65 | 66 | findPowerSet(S, set, n, maximum); 67 | 68 | printf("The maximum product of a subset is %d", maximum); 69 | printf(\n); 70 | 71 | return 0; 72 | } 73 | ``` 74 | 75 | -------------------------------------------------------------------------------- /Code/MaximumSubarray.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Raj Anand' 3 | Github: 'https://github.com/raazanand' 4 | WebSite: '' 5 | Problem: 'Maximum Subarray' 6 | Description: 'Find the contiguous subarray (containing at least one number) which has the largest sum and return its sum' 7 | Language: 'Java' 8 | --- 9 | 10 | ```java 11 | 12 | import java.util.Scanner; 13 | 14 | public class Solution { 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | System.out.println("Enter length of array"); 18 | int length = sc.nextInt(); 19 | int[] array = new int[length]; 20 | System.out.println("Enter array element"); 21 | for(int i = 0; i < length; i++) { 22 | array[i] = sc.nextInt(); 23 | } 24 | System.out.println(maxSubArray(array)); 25 | 26 | } 27 | public static int maxSubArray(int[] nums) { 28 | //Edge case, empty array 29 | if (nums.length == 0) { 30 | return 0; 31 | } 32 | 33 | int[] sums = new int[nums.length]; 34 | sums[0] = nums[0]; 35 | // origin problem & sub problem relation: 36 | //f(n) = max(nums[n],nums[n]+dp[n-1]) 37 | for (int i = 1; i < sums.length; i++) { 38 | sums[i] = Math.max(nums[i], nums[i] + sums[i-1]); 39 | } 40 | // find the max subarray sum 41 | int maxSum = Integer.MIN_VALUE; 42 | for (int sum : sums) { 43 | maxSum = (sum > maxSum) ? sum : maxSum; 44 | } 45 | return maxSum; 46 | } 47 | 48 | } 49 | 50 | ``` -------------------------------------------------------------------------------- /Code/MergeSort.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Kanishk Vijaywargiya' 3 | Github: 'https://github.com/KanishkVijaywargiya' 4 | WebSite: '' 5 | Problem: 'MergeSort in JavaScript' 6 | Description: 'Recursive method for sorting in JS' 7 | Language: 'JavaScript' 8 | --- 9 | ``` 10 | const arr = [23, 4, 67, 32, 1, 7, 56, 5, 89]; 11 | const mergeSort = arr => { 12 | if (arr.length < 2){ 13 | return arr; 14 | } 15 | const middle = Math.floor(arr.length / 2); 16 | const left = arr.slice(0, middle), right = arr.slice(middle, arr.length); 17 | return merge(mergeSort(left), mergeSort(right)); 18 | }; 19 | const merge = (left, right) => { 20 | const res = []; 21 | while (left.length && right.length) { 22 | if (left[0] <= right[0]){ 23 | res.push(left.shift()); 24 | } 25 | else{ 26 | res.push(right.shift()); 27 | }; 28 | } 29 | while (left.length){ 30 | res.push(left.shift()); 31 | }; 32 | while (right.length){ 33 | res.push(right.shift()); 34 | }; 35 | return res; 36 | }; 37 | console.log(mergeSort(arr)); 38 | 39 | ``` 40 | -------------------------------------------------------------------------------- /Code/N-queens.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Shivank srivastava' 3 | Github: 'https://github.com/shivank911' 4 | WebSite: 'https://github.com/shivank911' 5 | Problem: 'N-queens' 6 | Description: 'To place n queens in an NxN chessboard successfully.' 7 | Explanation: 'Size of the chess board whic is n is given by the user!' 8 | Language: 'JAVA' 9 | --- 10 | ```java 11 | import java.util.*; 12 | import java.io.*; 13 | import java.util.*; 14 | 15 | public class Nqueens { 16 | 17 | public static boolean IsQueenSafe(boolean[][] chess, int row, int col) { 18 | for(int i=col-1;i>=0;i--){ 19 | if(chess[row][i]==true) 20 | return false; 21 | } 22 | for(int i=row-1;i>=0;i--){ 23 | if(chess[i][col]==true) 24 | return false; 25 | } 26 | for(int i=row-1,j=col-1;i>=0 && j>=0;i--,j--){ 27 | if(chess[i][j]==true) 28 | return false; 29 | } 30 | for(int i=row-1,j=col+1;i>=0 && j nums; 14 | for (int i = 1; i < n; i++) { 15 | fact = fact * i; 16 | nums.push_back(i); 17 | } 18 | nums.push_back(n); 19 | string ans = ""; 20 | k = k - 1; 21 | while (true) { 22 | ans = ans + to_string(nums[k / fact]); 23 | nums.erase(nums.begin() + k / fact); 24 | if (nums.size() == 0) { 25 | break; 26 | } 27 | k = k % fact; 28 | fact = fact / nums.size(); 29 | } 30 | return ans; 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /Code/Permutations.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Saksham Negi' 3 | Github: 'https://github.com/sakshamian' 4 | Problem: 'Permutations' 5 | Description: 'Given a number n, generate all permutations of a set of n elements.' 6 | Language: 'cpp' 7 | --- 8 | 9 | ``` 10 | #include 11 | #define N 100002 12 | #define fast \ 13 | ios_base::sync_with_stdio(false); \ 14 | cin.tie(NULL); \ 15 | cout.tie(NULL) 16 | using namespace std; 17 | vector permutation; 18 | bool chose[N + 1]; 19 | void search(int n) 20 | { 21 | 22 | if (permutation.size() == n) 23 | { 24 | for (auto it : permutation) 25 | { 26 | cout << it << " "; 27 | } 28 | cout << '\n'; 29 | } 30 | else 31 | { 32 | for (int i = 1; i <= n; i++) 33 | { 34 | if (chose[i]) 35 | continue; 36 | chose[i] = true; 37 | permutation.push_back(i); 38 | search(n); 39 | chose[i] = false; 40 | permutation.pop_back(); 41 | } 42 | } 43 | } 44 | int main() 45 | { 46 | fast; 47 | int n; 48 | cin >> n; 49 | search(n); 50 | // } 51 | return 0; 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /Code/Playlist.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pranay Chauhan' 3 | Github: 'https://github.com/PranayChauhan2516' 4 | WebSite: 'https://cses.fi/problemset/task/1141/' 5 | Problem: 'Playlist' 6 | Description: 'Longest unique sequence' 7 | Language: 'Java' 8 | --- 9 | ```java 10 | 11 | import java.io.OutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.PrintWriter; 15 | import java.util.HashMap; 16 | import java.util.InputMismatchException; 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | 20 | /** 21 | * Built using CHelper plug-in 22 | * Actual solution is at the top 23 | * 24 | * @author Pranay2516 25 | */ 26 | public class Main { 27 | public static void main(String[] args) { 28 | InputStream inputStream = System.in; 29 | OutputStream outputStream = System.out; 30 | FastReader in = new FastReader(inputStream); 31 | PrintWriter out = new PrintWriter(outputStream); 32 | Playlist solver = new Playlist(); 33 | solver.solve(1, in, out); 34 | out.close(); 35 | } 36 | 37 | static class Playlist { 38 | public void solve(int testNumber, FastReader in, PrintWriter out) { 39 | int n = in.nextInt(); 40 | int[] a = in.readArray(n); 41 | HashMap h = new HashMap<>(); 42 | int ans = 0; 43 | int j = 0; 44 | for (int i = 0; i < n; ++i) { 45 | j = Math.max(j, h.getOrDefault(a[i], 0)); 46 | ans = Math.max(ans, i - j + 1); 47 | h.put(a[i], i + 1); 48 | } 49 | out.println(ans); 50 | } 51 | 52 | } 53 | 54 | static class FastReader { 55 | private InputStream stream; 56 | private byte[] buf = new byte[1024]; 57 | private int curChar; 58 | private int numChars; 59 | private FastReader.SpaceCharFilter filter; 60 | 61 | public FastReader(InputStream stream) { 62 | this.stream = stream; 63 | } 64 | 65 | public int read() { 66 | if (numChars == -1) throw new InputMismatchException(); 67 | if (curChar >= numChars) { 68 | curChar = 0; 69 | try { 70 | numChars = stream.read(buf); 71 | } catch (IOException e) { 72 | throw new InputMismatchException(); 73 | } 74 | if (numChars <= 0) return -1; 75 | } 76 | return buf[curChar++]; 77 | } 78 | 79 | public int nextInt() { 80 | int c = read(); 81 | while (isSpaceChar(c)) c = read(); 82 | int sgn = 1; 83 | if (c == '-') { 84 | sgn = -1; 85 | c = read(); 86 | } 87 | int res = 0; 88 | do { 89 | if (c < '0' || c > '9') throw new InputMismatchException(); 90 | res *= 10; 91 | res += c - '0'; 92 | c = read(); 93 | } 94 | while (!isSpaceChar(c)); 95 | return res * sgn; 96 | } 97 | 98 | public boolean isSpaceChar(int c) { 99 | if (filter != null) return filter.isSpaceChar(c); 100 | return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; 101 | } 102 | 103 | public int[] readArray(int size) { 104 | int[] array = new int[size]; 105 | for (int i = 0; i < size; i++) array[i] = nextInt(); 106 | return array; 107 | } 108 | 109 | public interface SpaceCharFilter { 110 | public boolean isSpaceChar(int ch); 111 | 112 | } 113 | 114 | } 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Code/Power-of-number.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pratibha Singh' 3 | Github: 'https://github.com/Crazy2code15' 4 | WebSite: 5 | Problem: 'Power-of-number' 6 | Description: 'Find Power of a number.' 7 | Explanation: 'Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.' 8 | Language: 'Python' 9 | --- 10 | 11 | ```py 12 | def powerof(a, b): 13 | results = 1 14 | for n in range(b): 15 | results *= a 16 | return results 17 | 18 | a, b = input().split() 19 | a = int(a) 20 | b = int(b) 21 | print(powerof(a,b)) 22 | ``` 23 | -------------------------------------------------------------------------------- /Code/PowerOfThree.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Raj Anand' 3 | Github: 'https://github.com/raazanand' 4 | WebSite: '' 5 | Problem: 'Power of Three' 6 | Description: 'Given an integer n, return true if it is a power of three. Otherwise, return false.' 7 | Language: 'Java' 8 | --- 9 | 10 | 11 | 12 | ```java 13 | 14 | import java.util.*; 15 | public class powerOfThree { 16 | 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | System.out.println("Enter element"); 20 | int n = sc.nextInt(); 21 | System.out.println(isPowerOfThree(n)); 22 | } 23 | 24 | public boolean isPowerOfThree(int n) { 25 | return helper((double) n); 26 | } 27 | private boolean helper(double n){ 28 | if(n<1) return false; 29 | 30 | if(n==3 || n==1) { 31 | return true; 32 | } 33 | return helper(n/3); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Code/PowerOfTwo.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Jaydeep Pipaliya' 3 | Github: 'https://github.com/jaydeep-pipaliya' 4 | WebSite: '' 5 | Problem: 'Check the Given Number is Power of 2 or not' 6 | Description: 'Calculating power Two in O(1)' 7 | Language: 'C++' 8 | --- 9 | ```C++ 10 | 11 | /* 12 | Used Bit manipulation 13 | 14 | Let's take some good exampes : 15 | number->binary form 16 | 3->0000 0011 17 | 4->0000 0100 18 | 5->0000 0101 19 | 6->0000 0110 20 | 7->0000 0111 21 | 8->0000 1000 22 | 23 | Now consider :- 24 | bit representation of 7 -> 0111 25 | bit representation of 8 -> 1000 26 | bitwise AND of 7 and 8 -> 0000 27 | we are gonna use this property for for all numbers which are powers of two 28 | 29 | */ 30 | #include 31 | using namespace std; 32 | 33 | bool isPowerOfTwo(int n) { 34 | if(n<=0) return false; 35 | return ((n&(n-1))==0); 36 | } 37 | 38 | int main() 39 | { 40 | int n; 41 | cin>>n; 42 | bool ans; 43 | ans=isPowerOfTwo(n); 44 | cout< 10 | using namespace std; 11 | 12 | // A Binary Tree Node 13 | struct Node 14 | { 15 | int data; 16 | struct Node *left, *right; 17 | }; 18 | 19 | // function to print leaf 20 | // nodes from left to right 21 | void printLeafNodes(Node *root) 22 | { 23 | // if node is null, return 24 | if (!root) 25 | return; 26 | 27 | // if node is leaf node, print its data 28 | if (!root->left && !root->right) 29 | { 30 | cout << root->data << " "; 31 | return; 32 | } 33 | 34 | // if left child exists, check for leaf 35 | // recursively 36 | if (root->left) 37 | printLeafNodes(root->left); 38 | 39 | // if right child exists, check for leaf 40 | // recursively 41 | if (root->right) 42 | printLeafNodes(root->right); 43 | } 44 | 45 | // Utility function to create a new tree node 46 | Node* newNode(int data) 47 | { 48 | Node *temp = new Node; 49 | temp->data = data; 50 | temp->left = temp->right = NULL; 51 | return temp; 52 | } 53 | 54 | int main() 55 | { 56 | // Let us create binary tree shown in 57 | // above diagram 58 | Node *root = newNode(1); 59 | root->left = newNode(2); 60 | root->right = newNode(3); 61 | root->left->left = newNode(4); 62 | root->right->left = newNode(5); 63 | root->right->right = newNode(8); 64 | root->right->left->left = newNode(6); 65 | root->right->left->right = newNode(7); 66 | root->right->right->left = newNode(9); 67 | root->right->right->right = newNode(10); 68 | 69 | // print leaf nodes of the given tree 70 | printLeafNodes(root); 71 | 72 | return 0; 73 | } 74 | ``` 75 | -------------------------------------------------------------------------------- /Code/Print_ALL_String_Subsequence.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'DragonUncaged' 3 | Github: 'https://github.com/DragonUncaged' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Print The Alll The subsequences Of String' 6 | Description: ' A String is a subsequence of a given String, that is generated by deleting some character of a given string without changing its order.' 7 | Explanation: 'One by one fix characters and recursively generates all subsets starting from them.' 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | /** 12 | Ex. 13 | Input: 14 | abc 15 | Output: 16 | abc 17 | ab 18 | ac 19 | a 20 | bc 21 | b 22 | c 23 | (empty) 24 | 25 | One by one fix characters and recursively generates all subsets starting from them. 26 | After every recursive call, we remove last character so that the next permutation can be generated. 27 | 28 | */ 29 | #include "bits/stdc++.h" 30 | using namespace std; 31 | 32 | vector v; 33 | vector> result; 34 | 35 | void subSequence(string &str, int i) 36 | { 37 | if (i == str.size()) 38 | { 39 | result.push_back(v); 40 | return; 41 | } 42 | char c = str[i]; 43 | v.push_back(c); 44 | subSequence(str, i + 1); //call for inclusion O(1) 45 | v.pop_back(); //restore to original; 46 | subSequence(str, i + 1); //call for exclusion 47 | } 48 | 49 | int main() 50 | { 51 | string str; 52 | cin >> str; 53 | //v and result are declared globally 54 | v.reserve(str.size()); 55 | result.reserve(1 << (str.size())); 56 | subSequence(str, 0); 57 | 58 | for (auto &row : result) 59 | { 60 | if (row.size() == 0) 61 | { 62 | cout << "(empty)\n"; 63 | continue; 64 | } 65 | 66 | for (auto &el : row) 67 | cout << el; 68 | cout << "\n"; 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | 75 | ``` -------------------------------------------------------------------------------- /Code/Product of 2 Numbers.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Krupal Patel' 3 | Github: 'https://github.com/iamkp1010' 4 | WebSite: '' 5 | Problem: 'Product of 2 Numbers' 6 | Description: 'Find Product of 2 Numbers using Recursion' 7 | Language: 'C++' 8 | --- 9 | 10 | ```C++ 11 | 12 | #include 13 | using namespace std; 14 | 15 | // recursive function to calculate 16 | // multiplication of two numbers 17 | int product(int x, int y) 18 | { 19 | // if x is less than 20 | // y swap the numbers 21 | if (x < y) 22 | return product(y, x); 23 | 24 | // iteratively calculate 25 | // y times sum of x 26 | else if (y != 0) 27 | return (x + product(x, y - 1)); 28 | 29 | // if any of the two numbers is 30 | // zero return zero 31 | else 32 | return 0; 33 | } 34 | 35 | int main() 36 | { 37 | int x = 5, y = 2; 38 | cout << product(x, y); 39 | return 0; 40 | } 41 | 42 | ``` -------------------------------------------------------------------------------- /Code/QuickSort.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Abhishek AB' 3 | Github: 'https://github.com/kehshiba' 4 | Problem: 'QuickSort in Python' 5 | Description: 'Recursive method - QuickSort' 6 | Language: 'Python' 7 | --- 8 | 9 | ```python 10 | def Quicksort(a, l, r): 11 | current = l+1 12 | if r <= current: 13 | return None 14 | for i in range(l+1, r): 15 | if a[l] >= a[i]: 16 | a[i], a[current] = a[current], a[i] 17 | current += 1 18 | a[l], a[current-1] = a[current-1], a[l] 19 | Quicksort(a, l, current-1) 20 | 21 | Quicksort(a, current, r) 22 | return None 23 | 24 | a = [5,6,4,12,9,2,1,7,6,3] 25 | print('Before sorting...') 26 | print(a) 27 | Quicksort(a, 0, len(a)) 28 | print('\nAfter sorting...') 29 | print(a) 30 | 31 | 32 | ``` 33 | -------------------------------------------------------------------------------- /Code/QuickSortJava.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/Code/QuickSortJava.md -------------------------------------------------------------------------------- /Code/RecursiveTernarySearch.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Divya Patel' 3 | Github: 'https://github.com/dd-712' 4 | WebSite: '' 5 | Problem: 'Ternary Search' 6 | Description: 'Search for given key in an array using Ternary Search recursively' 7 | Language: 'C++' 8 | --- 9 | 10 | ```C++ 11 | 12 | #include 13 | using namespace std; 14 | 15 | // to implement ternary search we require sorted array 16 | // we will divide array into three parts and will check 17 | // in which part our key might be present 18 | 19 | int ternarySearch(int l, int r, int key, int ar[]) 20 | { 21 | if (l > r) 22 | return -1; 23 | 24 | int mid1 = l + (r - l) / 3; 25 | int mid2 = r - (r - l) / 3; 26 | 27 | if (ar[mid1] == key) 28 | return mid1; 29 | if (ar[mid2] == key) 30 | return mid2; 31 | 32 | if (key < ar[mid1]) 33 | return ternarySearch(l, mid1 - 1, key, ar); 34 | else if (key > ar[mid2]) 35 | return ternarySearch(mid2 + 1, r, key, ar); 36 | else 37 | return ternarySearch(mid1 + 1, mid2 - 1, key, ar); 38 | 39 | return -1; 40 | } 41 | 42 | int main() 43 | { 44 | int n; 45 | cin >> n; 46 | int arr[n]; 47 | for (int i = 0; i < n; i++) 48 | cin >> arr[i]; 49 | 50 | int key; 51 | cin >> key; 52 | 53 | int index = ternarySearch(0, n, key, arr); 54 | 55 | if (index != -1) 56 | cout << key << " found at index " << index << endl; 57 | else 58 | cout << "Key not found"; 59 | } 60 | 61 | ``` -------------------------------------------------------------------------------- /Code/ReverseDoublyLinkedList.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ankit Raibole' 3 | Github: 'https://github.com/iota-008' 4 | WebSite: 'https://iota-008.github.io' 5 | Problem: 'Reverse a doubly linkedlist' 6 | Description: 'Reverse a doubly linkedlist using recursion' 7 | Language: 'C++' 8 | --- 9 | ```C++ 10 | /** 11 | Algorithm 12 | 1) If list is empty, return 13 | 2) Reverse head by swapping head->prev and head->next 14 | 3) If prev = NULL it means that list is fully reversed. Else reverse(head->prev) 15 | */ 16 | 17 | #include 18 | using namespace std; 19 | 20 | struct Node { 21 | int data; 22 | Node *next, *prev; 23 | }; 24 | 25 | Node* getNode(int data) 26 | { 27 | Node* new_node = new Node; 28 | new_node->data = data; 29 | new_node->next = new_node->prev = NULL; 30 | return new_node; 31 | } 32 | 33 | void push(Node** head_ref, Node* new_node) 34 | { 35 | new_node->prev = NULL; 36 | 37 | new_node->next = (*head_ref); 38 | 39 | if ((*head_ref) != NULL) 40 | (*head_ref)->prev = new_node; 41 | 42 | (*head_ref) = new_node; 43 | } 44 | 45 | Node* Reverse(Node* node) 46 | { 47 | if (!node) 48 | return NULL; 49 | 50 | Node* temp = node->next; 51 | node->next = node->prev; 52 | node->prev = temp; 53 | 54 | if (!node->prev) 55 | return node; 56 | 57 | return Reverse(node->prev); 58 | } 59 | 60 | void printList(Node* head) 61 | { 62 | while (head != NULL) { 63 | cout << head->data << " "; 64 | head = head->next; 65 | } 66 | } 67 | 68 | int main() 69 | { 70 | Node* head = NULL; 71 | 72 | int n; 73 | 74 | cout<<"Enter number of nodes you want to insert in list : "; 75 | cin>>n; 76 | 77 | for(int i=0; i>x; 81 | push(&head, getnode(x)); 82 | } 83 | 84 | cout << "Original list: "; 85 | printList(head); 86 | 87 | head = Reverse(head); 88 | cout << "\nReversed list: "; 89 | printList(head); 90 | return 0; 91 | } 92 | ``` -------------------------------------------------------------------------------- /Code/ReverseInGroups.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ashutosh Pandey' 3 | Github: 'https://github.com/Ashutoshpandey-coder' 4 | Problem: 'ReverseInGroups' 5 | Description: 'Reverse the Linked List in groups of K, using recusion.' 6 | Language: 'java' 7 | --- 8 | ```java 9 | 10 | /* PROBLEM STATEMENT 11 | * Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list. 12 | If the number of nodes is not a multiple of k then left-out nodes, in the end, should be considered as a group and must be reversed. 13 | */ 14 | /* EXAMPLE 1 */ 15 | /* INPUT 16 | * LinkedList: 1->2->2->4->5->6->7->8 17 | K = 4 18 | */ 19 | /* OUTPUT 20 | * 4 2 2 1 8 7 6 5 21 | */ 22 | 23 | /* EXAMPLE 2 */ 24 | /* INPUT 25 | * LinkedList: 1->2->3->4->5 26 | K = 3 27 | */ 28 | /* OUTPUT 29 | * 3 2 1 5 4 30 | */ 31 | 32 | import java.lang.*; 33 | import java.util.*; 34 | 35 | class Node{ 36 | int data; 37 | Node next; 38 | Node(int data){ 39 | this.data = data; 40 | next = null; 41 | } 42 | } 43 | public class ReverseInGroups { 44 | 45 | static Node head; 46 | 47 | static void printList(Node node){ 48 | while(node != null){ 49 | System.out.print(node.data + " "); 50 | node = node.next; 51 | } 52 | System.out.println(); 53 | } 54 | 55 | public static void main(String[] args){ 56 | Scanner sc = new Scanner(System.in); 57 | int t = sc.nextInt(); 58 | while(t>0){ 59 | int n = sc.nextInt(); 60 | Node head = new Node(sc.nextInt()); 61 | Node tail = head; 62 | for(int i = 1; i< n; i++){ 63 | tail.next = new Node(sc.nextInt()); 64 | tail = tail.next; 65 | } 66 | int k = sc.nextInt(); 67 | Solution sol = new Solution(); 68 | Node res = sol.Reversekth(head,k); 69 | printList(res); 70 | t--; 71 | } 72 | 73 | } 74 | 75 | } 76 | class Solution{ 77 | public static Node Reversekth(Node head, int k){ 78 | Node curr = head, next = null, prev = null; 79 | int count = 0; 80 | while(curr != null && count < k){ 81 | next = curr.next; 82 | curr.next = prev; 83 | prev = curr; 84 | curr = next; 85 | count++; 86 | } 87 | if(next != null){ 88 | Node rest_head = Reversekth(next,k); 89 | head.next = rest_head; 90 | } 91 | return prev; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Code/ReverseLinkedList.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Ankit Rao' 3 | Github: 'https://github.com/DragonUncaged' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Reverse Linked List' 6 | Description: 'For The Given linked List reverse the linked List And Print It.' 7 | Explanation: 'make the previous node of the current node as his next node to reverse the linked list..' 8 | Language: 'c++' 9 | 10 | --- 11 | ```c++ 12 | /* 13 | Ex. 14 | Input: 15 | 1 2 3 4 16 | Output: 17 | 4 3 2 1 18 | 19 | We return the pointer of next node to his previous(current) node and then make the previous node as the next node of returned node and then returning the current node. 20 | 21 | We first traverse till the last node and making the last node as the head node of reversed linked list and then applying the above procedure in the recursive manner. 22 | */ 23 | 24 | #include 25 | using namespace std; 26 | 27 | struct Node { 28 | int data; 29 | struct Node* next; 30 | Node(int data) 31 | { 32 | this->data = data; 33 | next = NULL; 34 | } 35 | }; 36 | 37 | struct LinkedList { 38 | Node* head; 39 | LinkedList() 40 | { 41 | head = NULL; 42 | } 43 | 44 | //reverse Linked List 45 | Node* reverse(Node* node) 46 | { 47 | if (node == NULL) 48 | return NULL; 49 | if (node->next == NULL) { 50 | head = node; 51 | return node; 52 | } 53 | Node* node1 = reverse(node->next); 54 | node1->next = node; 55 | node->next = NULL; 56 | return node; 57 | } 58 | 59 | void print() 60 | { 61 | struct Node* temp = head; 62 | while (temp != NULL) { 63 | cout << temp->data << " "; 64 | temp = temp->next; 65 | } 66 | } 67 | 68 | void push(int data) 69 | { 70 | Node* temp = new Node(data); 71 | temp->next = head; 72 | head = temp; 73 | } 74 | }; 75 | 76 | int main() 77 | { 78 | LinkedList ll; 79 | ll.push(1); 80 | ll.push(2); 81 | ll.push(3); 82 | ll.push(4); 83 | 84 | cout << "Given linked list\n"; 85 | ll.print(); 86 | 87 | ll.reverse(ll.head); 88 | 89 | cout << "\nReversed Linked list \n"; 90 | ll.print(); 91 | return 0; 92 | } 93 | 94 | 95 | ``` 96 | -------------------------------------------------------------------------------- /Code/ReverseStack.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'zgraceman' 3 | Github: 'https://github.com/zgraceman' 4 | WebSite: 'https://github.com/zgraceman' 5 | Problem: 'Reverse a Stack' 6 | Description: 'Given a stack of characters, reverse it using stack functions and recursion.' 7 | Explanation: 'See code below for solution' 8 | Language: 'java' 9 | --- 10 | 11 | ```java 12 | import java.util.Stack; 13 | 14 | class ReverseStack { 15 | 16 | static Stack stack = new Stack<>(); 17 | 18 | // Recursive function, inserts characters at bottom 19 | static void insert_at_bottom(char x) 20 | { 21 | if (stack.isEmpty()) 22 | stack.push(x); 23 | 24 | else { 25 | char a = stack.peek(); 26 | stack.pop(); 27 | insert_at_bottom(x); 28 | stack.push(a); 29 | } 30 | } 31 | 32 | static void reverse() 33 | { 34 | if (stack.size() > 0) { 35 | char x = stack.peek(); 36 | stack.pop(); 37 | reverse(); 38 | insert_at_bottom(x); 39 | } 40 | } 41 | 42 | // Main 43 | public static void main(String[] args) 44 | { 45 | // Initializing stack 46 | stack.push('1'); 47 | stack.push('2'); 48 | stack.push('3'); 49 | stack.push('4'); 50 | stack.push('5'); 51 | stack.push('6'); 52 | 53 | System.out.println("Original Stack"); 54 | System.out.println(stack); 55 | reverse(); 56 | System.out.println("Reversed Stack"); 57 | System.out.println(stack); 58 | } 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /Code/ReverseTheArray.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'DragonUncaged' 3 | Github: 'https://github.com/DragonUncaged' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Reverse_Array_Recursively' 6 | Description: 'For The Given Array and its Size reverse the Array And Print It.' 7 | Explanation: 'Just Swap the Value Of first to the Last second to the Second Last and so On..' 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | /** 12 | Ex. 13 | Input: 14 | 1 15 | 4 16 | 1 2 3 4 17 | Output: 18 | 4 3 2 1 19 | void function (arr,start ,end,size) 20 | 21 | Base Case : If Traversed to all the size 22 | 23 | //swap the values of start and end 24 | swap(arr[start], arr[end]); 25 | 26 | //Increase the value of start and Decrease the value of end 27 | reverseArr(arr, start + 1, end - 1, size); 28 | */ 29 | #include "bits/stdc++.h" 30 | using namespace std; 31 | 32 | void reverseArr(int arr[], int start, int end, int n) 33 | { 34 | if (start >= end) 35 | return; 36 | swap(arr[start], arr[end]); 37 | reverseArr(arr, start + 1, end - 1, n); 38 | } 39 | void PrintArr(int a[], int N) 40 | { 41 | for (int z = 1; z <= N; z++) 42 | cout << a[z] << " "; 43 | cout << endl; 44 | } 45 | 46 | signed main() 47 | { 48 | int N; 49 | cin >> N; 50 | int a[N]; 51 | loop(i, 0, N - 1) 52 | cin>>a[i]; 53 | 54 | reverseArr(a, 0, N, N); 55 | PrintArr(a, N); 56 | 57 | return 0; 58 | } 59 | 60 | ``` -------------------------------------------------------------------------------- /Code/Rotated_Palindrome_String.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Himanshu Malviya' 3 | Github: 'https://github.com/Himanshu664' 4 | Problem: 'Check if a string is a rotated palindrome or not' 5 | Description: 'Given a String, check if a string is a rotated palindrome or not' 6 | Language: 'java' 7 | --- 8 | 9 | 10 | ```java 11 | class Main 12 | { 13 | // Recursive function to check if `str[low…high]` is a palindrome or not 14 | public static boolean isPalindrome(String str, int low, int high) 15 | { 16 | return (low >= high) || (str.charAt(low) == str.charAt(high) && 17 | isPalindrome(str, low + 1, high - 1)); 18 | } 19 | 20 | // Function to check if a given string is a rotated palindrome or not 21 | public static boolean isRotatedPalindrome(String str) 22 | { 23 | // base case 24 | if (str == null) { 25 | return false; 26 | } 27 | 28 | // length of the given string 29 | int n = str.length(); 30 | 31 | // check for all rotations of the given string if it 32 | // is palindrome or not 33 | for (int i = 0; i < n; i++) 34 | { 35 | // in-place rotate the string by 1 unit 36 | str = str.substring(1) + str.charAt(0); 37 | 38 | // return true if the rotation is a palindrome 39 | if (isPalindrome(str, 0, n - 1)) { 40 | return true; 41 | } 42 | } 43 | 44 | // return false if no rotation is a palindrome 45 | return false; 46 | } 47 | 48 | public static void main(String[] args) 49 | { 50 | // palindromic string 51 | String str = "ABCDCBA"; 52 | 53 | // rotate it by 2 units 54 | str = str.substring(2) + str.substring(0, 2); 55 | 56 | if (isRotatedPalindrome(str)) { 57 | System.out.println("The string is a rotated palindrome"); 58 | } 59 | else { 60 | System.out.println("The string is not a rotated palindrome"); 61 | } 62 | } 63 | } 64 | ``` 65 | -------------------------------------------------------------------------------- /Code/Rotten_Oranges.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Yogesh kumar Yadav' 3 | Github: 'https://github.com/YogeshKumarYadav' 4 | Problem: 'how much time it will take to rot all oranges graph application' 5 | Description: 'given a matrix find time taken to rot all oranges place ' 6 | Language: 'c++' 7 | --- 8 | 9 | 10 | ```cpp 11 | 12 | 13 | #include 14 | using namespace std; 15 | 16 | // } Driver Code Ends 17 | 18 | 19 | class Solution 20 | { 21 | public: 22 | //Function to find minimum time required to rot all oranges. 23 | int orangesRotting(vector>& grid) 24 | { 25 | int n = grid.size(); 26 | int m = grid[0].size(); 27 | //vector> vis(n, vector(m,false)); 28 | queue> q1,q2; 29 | 30 | for(int i=0; i x = q1.front(); 42 | q1.pop(); 43 | int i = x.first; 44 | int j = x.second; 45 | grid[i][j]++; 46 | 47 | if(i+1 >=0 && i+1 < n && j >= 0 && j < m && grid[i+1][j] == 1) 48 | { 49 | q2.push(make_pair(i+1,j)); 50 | grid[i+1][j]++; 51 | } 52 | if(i >=0 && i < n && j+1 >= 0 && j+1 < m && grid[i][j+1] == 1) 53 | { 54 | q2.push(make_pair(i,j+1)); 55 | grid[i][j+1]++; 56 | } 57 | if(i-1 >=0 && i-1 < n && j >= 0 && j < m && grid[i-1][j] == 1) 58 | { 59 | q2.push(make_pair(i-1,j)); 60 | grid[i-1][j]++; 61 | } 62 | if(i >=0 && i < n && j-1 >= 0 && j-1 < m && grid[i][j-1] == 1) 63 | { 64 | q2.push(make_pair(i,j-1)); 65 | grid[i][j-1]++; 66 | } 67 | } 68 | if(!q2.empty()) 69 | count++; 70 | while(!q2.empty()) 71 | { 72 | pair x = q2.front(); 73 | q2.pop(); 74 | int i = x.first; 75 | int j = x.second; 76 | grid[i][j]++; 77 | 78 | if(i+1 >=0 && i+1 < n && j >= 0 && j < m && grid[i+1][j] == 1) 79 | { 80 | q1.push(make_pair(i+1,j)); 81 | grid[i+1][j]++; 82 | } 83 | if(i >=0 && i < n && j+1 >= 0 && j+1 < m && grid[i][j+1] == 1) 84 | { 85 | q1.push(make_pair(i,j+1)); 86 | grid[i][j+1]++; 87 | } 88 | if(i-1 >=0 && i-1 < n && j >= 0 && j < m && grid[i-1][j] == 1) 89 | { 90 | q1.push(make_pair(i-1,j)); 91 | grid[i-1][j]++; 92 | } 93 | if(i >=0 && i < n && j-1 >= 0 && j-1 < m && grid[i][j-1] == 1) 94 | { 95 | q1.push(make_pair(i,j-1)); 96 | grid[i][j-1]++; 97 | } 98 | } 99 | } 100 | for(int i=0; i> tc; 113 | while(tc--){ 114 | int n, m; 115 | cin >> n >> m; 116 | vector>grid(n, vector(m, -1)); 117 | for(int i = 0; i < n; i++){ 118 | for(int j = 0; j < m; j++){ 119 | cin >> grid[i][j]; 120 | } 121 | } 122 | Solution obj; 123 | int ans = obj.orangesRotting(grid); 124 | cout << ans << "\n"; 125 | } 126 | return 0; 127 | } // } Driver Code Ends 128 | ``` -------------------------------------------------------------------------------- /Code/SelectionSort.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Hasan Kataya' 3 | Github: 'https://github.com/Hkataya' 4 | WebSite: '' 5 | Problem: 'Recursive Selection Sort' 6 | Description: 'Sort an array of n elements using selection sort. Complexity O(n^2)' 7 | Explanation: 'Selection Sort works by splitting the arrary in a two subarrays (one sorted and one unsorted). In every iteration, the minimum element (ascending order) from the unsorted subarray is chosen and moved to the sorted subarray.' 8 | Language: 'java' 9 | --- 10 | 11 | ```java 12 | 13 | import java.util.Arrays; 14 | 15 | class SelectionSort 16 | { 17 | 18 | public static void selectionSort(int[] arr, int i, int n) 19 | { 20 | int min = i; 21 | int temp = 0; 22 | 23 | // find the minimum 24 | for (int j = i + 1; j < n; j++) 25 | if (arr[j] < arr[min]) 26 | min = j; 27 | 28 | // Swap minimum with current index 29 | temp = arr[min]; 30 | arr[min] = arr[i]; 31 | arr[i] = temp; 32 | 33 | if (i + 1 < n) 34 | selectionSort(arr, i + 1, n); 35 | } 36 | 37 | // Driver 38 | public static void main(String[] args) 39 | { 40 | int[] arr = { 3, 5, 8, 4, 1, 9, -2 }; 41 | selectionSort(arr, 0, arr.length); 42 | System.out.println(Arrays.toString(arr)); 43 | } 44 | 45 | } 46 | 47 | ``` 48 | -------------------------------------------------------------------------------- /Code/Shortest_path_in_maze.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Dinsha Jaiswal' 3 | Github: 'https://github.com/fleurdelis07' 4 | WebSite: 'https://www.linkedin.com/in/ankitrao/' 5 | Problem: 'Find the shortest path in a maze' 6 | Description: 'Given a maze in the form of binary rectangular matrix, find the shortest paths length in the maze.' 7 | Language: 'c++' 8 | --- 9 | ```c++ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | // Check if it is possible to go to (x, y) from the current position. The 18 | // function returns false if the cell has value 0 or already visited 19 | bool isSafe(vector> &mat, vector> &visited, int x, int y) 20 | { 21 | return (x >= 0 && x < mat.size() && y >= 0 && y < mat[0].size()) && 22 | mat[x][y] == 1 && !visited[x][y]; 23 | } 24 | 25 | // Find the shortest possible route in a matrix `mat` from source cell (i, j) 26 | // to destination cell (x, y). 27 | 28 | // `min_dist` is passed by reference and stores the length of the longest path 29 | // from source to a destination found so far, and `dist` maintains the length 30 | // of the path from a source cell to a current cell (i, j). 31 | 32 | void findShortestPath(vector> &mat, vector> &visited, 33 | int i, int j, int x, int y, int &min_dist, int dist) 34 | { 35 | // if the destination is found, update `min_dist` 36 | if (i == x && j == y) 37 | { 38 | min_dist = min(dist, min_dist); 39 | return; 40 | } 41 | 42 | // set (i, j) cell as visited 43 | visited[i][j] = true; 44 | 45 | // go to the bottom cell 46 | if (isSafe(mat, visited, i + 1, j)) { 47 | findShortestPath(mat, visited, i + 1, j, x, y, min_dist, dist + 1); 48 | } 49 | 50 | // go to the right cell 51 | if (isSafe(mat, visited, i, j + 1)) { 52 | findShortestPath(mat, visited, i, j + 1, x, y, min_dist, dist + 1); 53 | } 54 | 55 | // go to the top cell 56 | if (isSafe(mat, visited, i - 1, j)) { 57 | findShortestPath(mat, visited, i - 1, j, x, y, min_dist, dist + 1); 58 | } 59 | 60 | // go to the left cell 61 | if (isSafe(mat, visited, i, j - 1)) { 62 | findShortestPath(mat, visited, i, j - 1, x, y, min_dist, dist + 1); 63 | } 64 | 65 | // backtrack: remove (i, j) from the visited matrix 66 | visited[i][j] = false; 67 | } 68 | 69 | // Wrapper over findShortestPath() function 70 | int findShortestPathLength(vector> &mat, pair &src, 71 | pair &dest) 72 | { 73 | // base case: invalid input 74 | if (mat.size() == 0 || mat[src.first][src.second] == 0 || 75 | mat[dest.first][dest.second] == 0) { 76 | return -1; 77 | } 78 | 79 | // `M × N` matrix 80 | int M = mat.size(); 81 | int N = mat[0].size(); 82 | 83 | // construct an `M × N` matrix to keep track of visited cells 84 | vector> visited; 85 | visited.resize(M, vector(N)); 86 | 87 | int min_dist = INT_MAX; 88 | findShortestPath(mat, visited, src.first, src.second, dest.first, dest.second, 89 | min_dist, 0); 90 | 91 | if (min_dist != INT_MAX) { 92 | return min_dist; 93 | } 94 | 95 | return -1; 96 | } 97 | 98 | int main() 99 | { 100 | vector> mat = 101 | { 102 | { 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 }, 103 | { 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, 104 | { 0, 0, 1, 0, 1, 1, 1, 0, 0, 1 }, 105 | { 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 }, 106 | { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 }, 107 | { 1, 0, 1, 1, 1, 0, 0, 1, 1, 0 }, 108 | { 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 }, 109 | { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, 110 | { 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 }, 111 | { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1 }, 112 | }; 113 | 114 | pair src = make_pair(0, 0); 115 | pair dest = make_pair(7, 5); 116 | 117 | int min_dist = findShortestPathLength(mat, src, dest); 118 | if (min_dist != -1) 119 | { 120 | cout << "The shortest path from source to destination " 121 | "has length " << min_dist; 122 | } 123 | else { 124 | cout << "Destination cannot be reached from a given source"; 125 | } 126 | 127 | return 0; 128 | } 129 | ``` -------------------------------------------------------------------------------- /Code/SimplifiedKnapsackProblem.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Oleg Ataman' 3 | Github: 'https://github.com/OlegAtaman/' 4 | WebSite: '' 5 | Problem: 'Recursive solution of simplified knapsack problem' 6 | Description: 'In terminal we give our knapsack capasity after "-W" and gold bars weights after "-w". Example: "python knapsack.py -W 20 -w 4 5 7 12". Algorithm returns maximum gold weight that we can take.' 7 | Language: 'python' 8 | --- 9 | ```python 10 | import argparse 11 | 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument("-W", type=int) 14 | parser.add_argument("-w", type=int, nargs="+") 15 | args = parser.parse_args() 16 | 17 | evrvar = [] 18 | 19 | 20 | def knapsack(capacity, weight, now=[]): 21 | weightn = sum(now) 22 | if weightn <= capacity: 23 | evrvar.append(weightn) 24 | for i in range(len(weight)): 25 | n = weight[i] 26 | left = weight[i+1:] 27 | knapsack(capacity, left, now+[n]) 28 | 29 | 30 | knapsack(args.W, args.w) 31 | print(max(evrvar)) 32 | ``` -------------------------------------------------------------------------------- /Code/Sortastack.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Abhijai Rajawat' 3 | Github: 'https://github.com/Severus25' 4 | Problem: 'Sort a Stack using Recursion' 5 | Description: 'Given a stack, the task is to sort it using recursion.' 6 | Language: 'C++' 7 | --- 8 | ```C++ 9 | 10 | #include 11 | using namespace std; 12 | 13 | // Stack is represented using linked list 14 | struct stack { 15 | int data; 16 | struct stack* next; 17 | }; 18 | 19 | // Utility function to initialize stack 20 | void initStack(struct stack** s) { *s = NULL; } 21 | 22 | // Utility function to check if stack is empty 23 | int isEmpty(struct stack* s) 24 | { 25 | if (s == NULL) 26 | return 1; 27 | return 0; 28 | } 29 | 30 | // Utility function to push an item to stack 31 | void push(struct stack** s, int x) 32 | { 33 | struct stack* p = (struct stack*)malloc(sizeof(*p)); 34 | 35 | if (p == NULL) { 36 | fprintf(stderr, "Memory allocation failed.\n"); 37 | return; 38 | } 39 | 40 | p->data = x; 41 | p->next = *s; 42 | *s = p; 43 | } 44 | 45 | // Utility function to remove an item from stack 46 | int pop(struct stack** s) 47 | { 48 | int x; 49 | struct stack* temp; 50 | 51 | x = (*s)->data; 52 | temp = *s; 53 | (*s) = (*s)->next; 54 | free(temp); 55 | 56 | return x; 57 | } 58 | 59 | // Function to find top item 60 | int top(struct stack* s) { return (s->data); } 61 | 62 | // Recursive function to insert an item x in sorted way 63 | void sortedInsert(struct stack** s, int x) 64 | { 65 | // Base case: Either stack is empty or newly inserted 66 | // item is greater than top (more than all existing) 67 | if (isEmpty(*s) or x > top(*s)) { 68 | push(s, x); 69 | return; 70 | } 71 | 72 | // If top is greater, remove the top item and recur 73 | int temp = pop(s); 74 | sortedInsert(s, x); 75 | 76 | // Put back the top item removed earlier 77 | push(s, temp); 78 | } 79 | 80 | // Function to sort stack 81 | void sortStack(struct stack** s) 82 | { 83 | // If stack is not empty 84 | if (!isEmpty(*s)) { 85 | // Remove the top item 86 | int x = pop(s); 87 | 88 | // Sort remaining stack 89 | sortStack(s); 90 | 91 | // Push the top item back in sorted stack 92 | sortedInsert(s, x); 93 | } 94 | } 95 | 96 | // Utility function to print contents of stack 97 | void printStack(struct stack* s) 98 | { 99 | while (s) { 100 | cout << s->data << " "; 101 | s = s->next; 102 | } 103 | cout << "\n"; 104 | } 105 | 106 | // Driver code 107 | int main(void) 108 | { 109 | struct stack* top; 110 | 111 | initStack(&top); 112 | push(&top, 30); 113 | push(&top, -5); 114 | push(&top, 18); 115 | push(&top, 14); 116 | push(&top, -3); 117 | 118 | cout << "Stack elements before sorting:\n"; 119 | printStack(top); 120 | 121 | sortStack(&top); 122 | cout << "\n"; 123 | 124 | cout << "Stack elements after sorting:\n"; 125 | printStack(top); 126 | 127 | return 0; 128 | } 129 | ``` 130 | -------------------------------------------------------------------------------- /Code/SourceToDestination.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Harsh-Oza' 3 | Github: 'https://github.com/HarshOza36' 4 | WebSite: 'http://harshoza.herokuapp.com/' 5 | Problem: 'Source to Destination' 6 | Description: 'Given 2D matrix with a source and destination, you have two moves down and right. Find total number of ways to reach from source to destination.' 7 | Language: 'python' 8 | --- 9 | ```python 10 | visited = {} 11 | def safe_to_go(a,b,m,n): 12 | if((a,b) in visited): 13 | if(a>=0 and a=0 and b=0 and a=0 and b= numChars) { 65 | curChar = 0; 66 | try { 67 | numChars = stream.read(buf); 68 | } catch (IOException e) { 69 | throw new InputMismatchException(); 70 | } 71 | if (numChars <= 0) return -1; 72 | } 73 | return buf[curChar++]; 74 | } 75 | 76 | public int nextInt() { 77 | int c = read(); 78 | while (isSpaceChar(c)) c = read(); 79 | int sgn = 1; 80 | if (c == '-') { 81 | sgn = -1; 82 | c = read(); 83 | } 84 | int res = 0; 85 | do { 86 | if (c < '0' || c > '9') throw new InputMismatchException(); 87 | res *= 10; 88 | res += c - '0'; 89 | c = read(); 90 | } 91 | while (!isSpaceChar(c)); 92 | return res * sgn; 93 | } 94 | 95 | public long nextLong() { 96 | int c = read(); 97 | while (isSpaceChar(c)) c = read(); 98 | int sgn = 1; 99 | if (c == '-') { 100 | sgn = -1; 101 | c = read(); 102 | } 103 | long res = 0; 104 | do { 105 | if (c < '0' || c > '9') throw new InputMismatchException(); 106 | res *= 10; 107 | res += c - '0'; 108 | c = read(); 109 | } while (!isSpaceChar(c)); 110 | return res * sgn; 111 | } 112 | 113 | public boolean isSpaceChar(int c) { 114 | if (filter != null) return filter.isSpaceChar(c); 115 | return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; 116 | } 117 | 118 | public long[] readLongArray(int size) { 119 | long[] array = new long[size]; 120 | for (int i = 0; i < size; i++) array[i] = nextLong(); 121 | return array; 122 | } 123 | 124 | public interface SpaceCharFilter { 125 | public boolean isSpaceChar(int ch); 126 | 127 | } 128 | 129 | } 130 | } 131 | 132 | ``` 133 | -------------------------------------------------------------------------------- /Code/StringCreation.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Saksham Negi' 3 | Github: 'https://github.com/shelendravashishtha2' 4 | WebSite: 'https://shelendravashishtha2.github.io/portfolio/' 5 | Problem: 'String Creation' 6 | Description: 'Given a string, generate all different strings that can be created using its characters in alphabetical order. ' 7 | Explanation: 'First print an integer k: the number of strings. 8 | Then print k lines: the strings in alphabetical order. 9 | Input: 10 | abc 11 | Output: 12 | 6 13 | abc 14 | acb 15 | bac 16 | bca 17 | cab 18 | cba 19 | ' 20 | Language: 'cpp' 21 | --- 22 | ```java 23 | import java.util.*; 24 | 25 | public class Factorial { 26 | public static long fact(int n) { 27 | if (n == 1) { 28 | return 1; 29 | } 30 | return n * fact(n - 1); 31 | } 32 | 33 | public static void main(String[] args) { 34 | Scanner s = new Scanner(System.in); 35 | System.out.println(fact(s.nextInt())); 36 | } 37 | } 38 | ``` -------------------------------------------------------------------------------- /Code/Subsequences.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Soham Sen' 3 | Github: 'https://github.com/NuclearCactus' 4 | Problem: 'Subsequences' 5 | Description: 'Print all the subsequences (power set) of a given string' 6 | Language: 'C++' 7 | --- 8 | 9 | ```C++ 10 | /* 11 | 12 | A subsequence is a set of characters from the string given in order. 13 | Ex. If the string is "abcd" 14 | Subsequences are: "", "a", "b", "c", "d", "ab", "ac", "ad", "bc", "bd", "cd", "abc", "abd", "acd", "bcd", "abcd" 15 | 16 | The solution to this problem passes partitioned strings into a recursive function and prints the final subsequence at the base case 17 | 18 | */ 19 | 20 | #include 21 | using namespace std; 22 | 23 | void subseq(string input, string output) { 24 | if(input.length() == 0) 25 | { // once input string becomes "", we print the output string, which is one of the subsets 26 | cout << output << endl; 27 | return; 28 | } 29 | // on each iteration we call the function twice with the output string once passed singly, and on the other case passed concatenated with the first letter of the input string 30 | subseq(input.substr(1), output); 31 | subseq(input.substr(1), output + input[0]); 32 | } 33 | 34 | int main() 35 | { // main function 36 | string word; 37 | cin >> word; 38 | subseq(word, ""); 39 | return 0; 40 | } 41 | ``` -------------------------------------------------------------------------------- /Code/Sum of Digits.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Saksham Negi' 3 | Github: 'https://github.com/sakshamian' 4 | Problem: 'Sum Of Digits' 5 | Description: 'Given a number, you need to find sum of its digits using recursion.' 6 | Language: 'cpp' 7 | --- 8 | 9 | ```C 10 | #include 11 | using namespace std; 12 | 13 | #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 14 | typedef long long ll; 15 | typedef unsigned long long ull; 16 | typedef long double lld; 17 | 18 | 19 | ll compute(ll n){ 20 | if(n==0){ 21 | return 0; 22 | } 23 | return (n%10 + compute(n/10)); 24 | } 25 | 26 | void solve(){ 27 | ll n; cin>>n; 28 | cout< "); 35 | ptr = ptr.next; 36 | } 37 | 38 | System.out.println("null"); 39 | } 40 | 41 | // function to pairwise swap adjacent nodes of the linked list 42 | public static Node rearrange(Node head, Node prev) 43 | { 44 | // base case 45 | if (head == null || head.next == null) { 46 | return head; 47 | } 48 | 49 | Node curr = head; 50 | Node temp = curr.next; 51 | curr.next = temp.next; 52 | temp.next = curr; 53 | 54 | if (prev == null) { 55 | head = temp; 56 | } 57 | else { 58 | prev.next = temp; 59 | } 60 | 61 | prev = curr; 62 | rearrange(curr.next, prev); 63 | 64 | return head; 65 | } 66 | 67 | public static Node rearrange(Node head) { 68 | return rearrange(head, null); 69 | } 70 | 71 | public static void main(String[] args) 72 | { 73 | int[] arr = { 1,2,3,4 }; 74 | 75 | Node head = null; 76 | for (int i = arr.length - 1; i >= 0; i--) { 77 | head = new Node(arr[i], head); 78 | } 79 | 80 | printList("Before : ", head); 81 | head = rearrange(head); 82 | printList("After : ", head); 83 | } 84 | } 85 | ``` 86 | -------------------------------------------------------------------------------- /Code/ThreeSum.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Raj Anand' 3 | Github: 'https://github.com/raazanand' 4 | WebSite: '' 5 | Problem: 'Three Sum' 6 | Description: 'Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. 7 | Notice that the solution set must not contain duplicate triplets.' 8 | Language: 'Java' 9 | --- 10 | 11 | ```java 12 | import java.util.*; 13 | 14 | public class threeSumLeetcode { 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | System.out.println("Enter length of array"); 18 | int length = sc.nextInt(); 19 | int[] array = new int[length]; 20 | System.out.println("Enter array element"); 21 | for(int i = 0; i < length; i++) { 22 | array[i] = sc.nextInt(); 23 | } 24 | List> ans = threeSum(array); 25 | 26 | for(List list: ans) { 27 | System.out.print("["); 28 | for(Integer ele: list) { 29 | System.out.print(ele + ", "); 30 | } 31 | System.out.print("]"); 32 | System.out.println(); 33 | } 34 | } 35 | public static List> threeSum(int[] nums) { 36 | List> ll = new ArrayList<>(); 37 | Arrays.sort(nums); 38 | for(int i=0;i0 && nums[i]==nums[i-1]){ 41 | continue; 42 | } 43 | int l=i+1, r=nums.length-1; 44 | while(l> ans = threeSum(array); 25 | 26 | for(List list: ans) { 27 | System.out.print("["); 28 | for(Integer ele: list) { 29 | System.out.print(ele + ", "); 30 | } 31 | System.out.print("]"); 32 | System.out.println(); 33 | } 34 | } 35 | public static List> threeSum(int[] nums) { 36 | List> ll = new ArrayList<>(); 37 | Arrays.sort(nums); 38 | for(int i=0;i0 && nums[i]==nums[i-1]){ 41 | continue; 42 | } 43 | int l=i+1, r=nums.length-1; 44 | while(l 13 | using namespace std; 14 | 15 | // In this puzzel we have n disks and 3 rods 16 | // All the disk are on rod A and our objective is to bring all the disks 17 | // on C by following given rules 18 | // 1. One disk can me moved at a time 19 | // 2. Disk can be moved from top of the stack of a rod to top of the stack of another rod 20 | // 3. No disk should be placed on smaller disk 21 | 22 | // this function will print the steps to achieve our objective 23 | void tOH(int n, char from, char to, char aux) 24 | { 25 | if (n == 1) 26 | { 27 | cout << "Move " << n << ": " << from << "----->" << to << endl; 28 | return; 29 | } 30 | 31 | tOH(n - 1, from, aux, to); 32 | cout << "Move " << n << ": " << from << "----->" << to << endl; 33 | tOH(n - 1, aux, to, from); 34 | } 35 | 36 | int main() 37 | { 38 | int n; 39 | // number of discs 40 | cin >> n; 41 | 42 | // A,B,C are the rods 43 | tOH(n, 'A', 'C', 'B'); 44 | 45 | return 0; 46 | } 47 | 48 | ``` -------------------------------------------------------------------------------- /Code/TwoSum.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Raj Anand' 3 | Github: 'https://github.com/raazanand' 4 | WebSite: '' 5 | Problem: 'Two Sum' 6 | Description: 'Given an array of integers numbers and an integer target, return indices of the two numbers such that they add up to target. 7 | You may assume that each input would have exactly one solution, and you may not use the same element twice. 8 | You can return the answer in any order.' 9 | Language: 'Java' 10 | --- 11 | 12 | ```java 13 | import java.util.*; 14 | 15 | public class twoSumLeetcode { 16 | static Mapmap = new HashMap(); 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | System.out.println("Enter length of array"); 20 | int length = sc.nextInt(); 21 | int[] array = new int[length]; 22 | System.out.println("Enter array element"); 23 | for(int i = 0; i < length; i++) { 24 | array[i] = sc.nextInt(); 25 | } 26 | System.out.println("Enter target element"); 27 | int target = sc.nextInt(); 28 | 29 | int[] ans = twoSum(array,target); 30 | System.out.println("index "+ans[0] +","+ "index "+ans[1]); 31 | } 32 | public static int[] twoSum(int[] nums, int target){ 33 | return twoSum2(nums, target, 0); 34 | } 35 | public static int[] twoSum2(int[] nums, int target, int i) { 36 | int lookUp = target-nums[i]; 37 | if(map.containsKey(lookUp)){ 38 | return new int []{map.get(lookUp), i}; 39 | }else{ 40 | map.put(nums[i],i); 41 | return twoSum2(nums,target, ++i); 42 | } 43 | } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /Code/UniqueBinarySearchTrees.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: "Sujata Choudhary" 3 | Github: "https://github.com/sujatachoudhary598" 4 | WebSite: "" 5 | Problem: "Unique Binary Search Trees" 6 | Description: "Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n." 7 | Language: "Java" 8 | --- 9 | 10 | ```java 11 | public class Solution { 12 | public int numTrees(int n) { 13 | Map map = new HashMap(); 14 | map.put(0,1); 15 | map.put(1,1); 16 | return numTrees(n, map); 17 | } 18 | 19 | private int numTrees(int n, Map map){ 20 | // check memory 21 | if(map.containsKey(n)) return map.get(n); 22 | // recursion 23 | int sum = 0; 24 | for(int i = 1;i <= n;i++) 25 | sum += numTrees(i-1, map) * numTrees(n-i, map); 26 | map.put(n, sum); 27 | return sum; 28 | } 29 | } 30 | 31 | ``` -------------------------------------------------------------------------------- /Code/add_digits.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'AlexMoonP' 3 | Github: 'https://github.com/AlexLunaP' 4 | WebSite: '' 5 | Problem: 'Add the digits of a number' 6 | Description: 'This program uses recursion calculate the addition of digits from a number given by the user.' 7 | Language: 'C' 8 | --- 9 | ```C 10 | #include 11 | 12 | int addDigits(int number, int sum){ 13 | if(number<10){ 14 | return number; 15 | } 16 | else{ 17 | sum=sum+((number%10)+(addDigits(number/10, sum))); //Recursive call to function addDigits; 18 | return sum; 19 | } 20 | 21 | } 22 | 23 | int main(){ 24 | int number; 25 | int sum=0; 26 | printf("Introduce a number to add its digits\n"); 27 | scanf("%i", &number); 28 | printf("The addition of the digits of number %i is: %i", number,addDigits(number, sum)); 29 | 30 | return 0; 31 | } 32 | ``` -------------------------------------------------------------------------------- /Code/delete_kth_node_from_linkedList.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Rajib Mondal' 3 | Github: 'https://github.com/mondalraj' 4 | WebSite: 'https://www.linkedin.com/in/dev-rajib-mondal/' 5 | Problem: 'Deleting k-th node from linked list' 6 | Description: 'Given a singly linked list, delete a node at the kth position without using the loop.' 7 | Language: 'java' 8 | --- 9 | ```java 10 | /** 11 | Given a singly linked list, delete a node at the kth position without using the loop. 12 | Example - 13 | Input : list = 9->8->3->5->2->1 14 | k = 4 15 | Output : 9->8->3->2->1 16 | 17 | Input : list = 0->0->1->6->2->3 18 | k = 3 19 | Output : 0->0->6->2->3 20 | */ 21 | 22 | class deleteKthNode 23 | { 24 | 25 | static class Node 26 | { 27 | int data; 28 | Node next; 29 | }; 30 | 31 | static Node deleteNode(Node start, int k) 32 | { 33 | if (k < 1) 34 | return start; 35 | 36 | if (start == null) 37 | return null; 38 | 39 | if (k == 1) 40 | { 41 | Node res = start.next; 42 | return res; 43 | } 44 | 45 | start.next = deleteNode(start.next, k-1); 46 | return start; 47 | } 48 | 49 | static Node push( Node head_ref, int new_data) 50 | { 51 | Node new_node = new Node(); 52 | new_node.data = new_data; 53 | new_node.next = head_ref; 54 | head_ref = new_node; 55 | return head_ref; 56 | } 57 | 58 | static void printList( Node head) 59 | { 60 | while (head!=null) 61 | { 62 | System.out.print(head.data + " "); 63 | head = head.next; 64 | } 65 | System.out.printf("\n"); 66 | } 67 | 68 | public static void main(String args[]) 69 | { 70 | Node head = null; 71 | 72 | head=push(head,3); 73 | head=push(head,2); 74 | head=push(head,6); 75 | head=push(head,5); 76 | head=push(head,11); 77 | head=push(head,10); 78 | head=push(head,15); 79 | head=push(head,12); 80 | 81 | int k = 3; 82 | head = deleteNode(head, k); 83 | 84 | System.out.printf("\nModified Linked List: "); 85 | printList(head); 86 | } 87 | } 88 | ``` 89 | -------------------------------------------------------------------------------- /Code/diameter_of_tree.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: "Abhijeet anand" 3 | Github: "abhijeet-crypto" 4 | WebSite: "" 5 | Problem: "diameter of a binary tree" 6 | Description: "find diameter of a tree using recursion in O(n) time" 7 | Language: "c++" 8 | --- 9 | 10 | ```c++ 11 | 12 | 13 | // Recursive optimized C program to find the diameter of a 14 | // Binary Tree 15 | 16 | #include 17 | using namespace std; 18 | 19 | struct node { 20 | int data; 21 | struct node *left, *right; 22 | }; 23 | struct node* newNode(int data); 24 | int max(int a, int b) { return (a > b) ? a : b; } 25 | int height(struct node* node); 26 | 27 | int diameter(struct node* tree) 28 | { 29 | // base case where tree is empty 30 | if (tree == NULL) 31 | return 0; 32 | 33 | // get the height of left and right sub-trees 34 | int lheight = height(tree->left); 35 | int rheight = height(tree->right); 36 | 37 | // get the diameter of left and right sub-trees 38 | int ldiameter = diameter(tree->left); 39 | int rdiameter = diameter(tree->right); 40 | 41 | return max(lheight + rheight + 1, 42 | max(ldiameter, rdiameter)); 43 | } 44 | 45 | 46 | 47 | int height(struct node* node) 48 | { 49 | 50 | if (node == NULL) 51 | return 0; 52 | 53 | return 1 + max(height(node->left), height(node->right)); 54 | } 55 | 56 | 57 | struct node* newNode(int data) 58 | { 59 | struct node* node 60 | = (struct node*)malloc(sizeof(struct node)); 61 | node->data = data; 62 | node->left = NULL; 63 | node->right = NULL; 64 | 65 | return (node); 66 | } 67 | 68 | // Driver Code 69 | int main() 70 | { 71 | 72 | struct node* root = newNode(1); 73 | root->left = newNode(2); 74 | root->right = newNode(3); 75 | root->left->left = newNode(4); 76 | root->left->right = newNode(5); 77 | 78 | // Function Call 79 | cout << "Diameter of the given binary tree is " 80 | << diameter(root); 81 | 82 | return 0; 83 | } 84 | 85 | ``` 86 | -------------------------------------------------------------------------------- /Code/factorial recursion.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Scientist69' 3 | Github: 'https://github.com/Scientist69' 4 | Problem: 'Factorial of a number' 5 | Description: 'Find the Factorial of a given number.' 6 | Language: 'c' 7 | --- 8 | ``` 9 | #include 10 | int fact (int); 11 | int main() 12 | { 13 | int n,f; 14 | printf("Enter the number whose factorial you want to calculate?"); 15 | scanf("%d",&n); 16 | f = fact(n); 17 | printf("factorial = %d",f); 18 | } 19 | int fact(int n) 20 | { 21 | if (n==0) 22 | { 23 | return 0; 24 | } 25 | else if ( n == 1) 26 | { 27 | return 1; 28 | } 29 | else 30 | { 31 | return n*fact(n-1); 32 | } 33 | } 34 | ``` 35 | -------------------------------------------------------------------------------- /Code/factorial_recursive.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Shivam Jindal' 3 | Github: 'https://github.com/Shivamjindal1' 4 | WebSite: 'https://shivamjindal1.github.io/website' 5 | Problem: 'Print Factorial of any number' 6 | Description: 'For The Given number n print its factorial.' 7 | Language: 'Python' 8 | --- 9 | ```py 10 | # Factorial of any number using python 11 | def factorial_recursive(n): 12 | """ 13 | :param n: Integer 14 | :return: n * n-1 * n-2 * n-3.......1 15 | """ 16 | if n ==1: 17 | return 1 18 | else: 19 | return n * factorial_recursive(n-1) 20 | 21 | number = int(input("Enter then number")) 22 | print(factorial_recursive(number)) 23 | ``` 24 | -------------------------------------------------------------------------------- /Code/googleDriveNestedFolderAccess.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'PiratePie' 3 | Github: 'https://github.com/Piratepie' 4 | WebSite: 'https://github.com/Piratepie' 5 | Problem: 'When removing access to a folder, the files inside are still accessible' 6 | Description: 'When removing access to a folder the user that had access to the folder can still access the files inside the folder, which is a security risk.' 7 | Language: 'Apps Script' 8 | --- 9 | 10 | ```Apps Script 11 | function removeAccess(folderId, editorEmail) { 12 | const currFolder = DriveApp.getFolderById(folderId); 13 | const allFolders = currFolder.getFolders(); 14 | const allFiles = currFolder.getFiles(); 15 | 16 | if (allFolders.hasNext()) { 17 | while (allFolders.hasNext()) { 18 | const nextFolder = allFolders.next(); 19 | removeAccess(nextFolder.getId()); 20 | } 21 | } 22 | 23 | if (allFiles.hasNext()) { 24 | while (allFiles.hasNext()) { 25 | const nextFile = allFiles.next(); 26 | nextFile.removeEditor(editorEmail); 27 | } 28 | } 29 | 30 | currFolder.removeEditor(editorEmail); 31 | } 32 | ``` -------------------------------------------------------------------------------- /Code/gridPaths.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Pranay Chauhan' 3 | Github: 'https://github.com/PranayChauhan2516' 4 | WebSite: 'https://cses.fi/problemset/task/1625' 5 | Problem: 'GridPaths' 6 | Description: 'Number of paths which match the description' 7 | Language: 'C++' 8 | --- 9 | ```c++ 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define n 7 15 | 16 | string c; 17 | long ans; 18 | bool vis[n][n]; 19 | 20 | 21 | bool valid(int i, int j) { 22 | return i>=0 && j>=0 && i>c; 69 | go(0,0,0); 70 | cout<0){ 18 | r=n%10; //getting remainder 19 | sum=(sum*10)+r; 20 | n=n/10; 21 | } 22 | if(temp==sum) 23 | System.out.println("palindrome number "); 24 | else 25 | System.out.println("not palindrome"); 26 | } 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /Code/print-array-using-recursion.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Rahul Khattri' 3 | Github: 'https://github.com/rahulkhattri0' 4 | Problem: 'Write a program in C to print the array elements using recursion.' 5 | Description: 'print array elements using recursion' 6 | Language: 'C' 7 | --- 8 | 9 | ```C 10 | #include 11 | #define MAX 100 12 | 13 | void ArrayElement(int arr1[], int st, int l); 14 | 15 | int main() 16 | { 17 | int arr1[MAX]; 18 | int n, i; 19 | printf("\n\n Recursion : Print the array elements :\n"); 20 | printf("-------------------------------------------\n"); 21 | 22 | printf(" Input the number of elements to be stored in the array :"); 23 | scanf("%d",&n); 24 | 25 | printf(" Input %d elements in the array :\n",n); 26 | for(i=0;i= l) 41 | return; 42 | 43 | //Prints the current array element 44 | printf("%d ", arr1[st]); 45 | 46 | /* Recursively call ArrayElement to print next element in the array */ 47 | ArrayElement(arr1, st+1, l);//calling the function ArrayElement itself 48 | } 49 | ``` -------------------------------------------------------------------------------- /Code/print_KPC.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Manju Thakur' 3 | Github: 'https://github.com/mthakur7' 4 | Problem: 'print KPC' 5 | Description: 'To print the list of all KPC' 6 | Language: 'java' 7 | --- 8 | ```java 9 | import java.io.*; 10 | import java.util.*; 11 | 12 | public class Main { 13 | 14 | public static void main(String[] args) throws Exception { 15 | Scanner scn=new Scanner(System.in); 16 | String str=scn.next(); 17 | printKPC(str,""); 18 | } 19 | static String[] codes={".;","abc","def","ghi","jkl","mno","pqrs","tu","vwx","yz"}; 20 | public static void printKPC(String str, String asf) { 21 | if(str.length()==0){ 22 | System.out.println(asf); 23 | return; 24 | } 25 | 26 | char ch=str.charAt(0); 27 | String ros=str.substring(1); 28 | 29 | String codeforch=codes[ch-'0']; 30 | for(int i=0;i 12 | using namespace std; 13 | 14 | /* Function to reverse arr[] from start to end*/ 15 | void rvereseArray(int arr[], int start, int end) 16 | { 17 | while (start < end) 18 | { 19 | int temp = arr[start]; 20 | arr[start] = arr[end]; 21 | arr[end] = temp; 22 | start++; 23 | end--; 24 | } 25 | } 26 | 27 | /* Utility function to print an array */ 28 | void printArray(int arr[], int size) 29 | { 30 | for (int i = 0; i < size; i++) 31 | cout << arr[i] << " "; 32 | 33 | cout << endl; 34 | } 35 | 36 | /* Driver function to test above functions */ 37 | int main() 38 | { 39 | int arr[] = {1, 2, 3, 4, 5, 6}; 40 | 41 | int n = sizeof(arr) / sizeof(arr[0]); 42 | 43 | // To print original array 44 | printArray(arr, n); 45 | 46 | // Function calling 47 | rvereseArray(arr, 0, n-1); 48 | 49 | cout << "Reversed array is" << endl; 50 | 51 | // To print the Reversed array 52 | printArray(arr, n); 53 | 54 | return 0; 55 | } 56 | 57 | ``` 58 | 59 | 60 | -------------------------------------------------------------------------------- /Code/rotateimage.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Jaydeep Pipaliya' 3 | Github: 'https://github.com/jaydeep-pipaliya' 4 | WebSite: '' 5 | Problem: 'Rotate image' 6 | Description: 'rotate the given matrix in clockwise direction' 7 | Explanation : We will transport the matrix and reverse the columns. 8 | Language: 'c++' 9 | --- 10 | ```c++ 11 | 12 | class Solution { 13 | public: 14 | void rotate(vector>& M) { 15 | int n = M.size(); 16 | 17 | //First transpose the matrix once! 18 | for (int i = 0; i < n; i++) { 19 | for (int j = 0; j < i; j++) { 20 | swap(M[i][j], M[j][i]); 21 | } 22 | } 23 | 24 | //Reverse every column! 25 | for(int i=0; i 11 | #include 12 | 13 | int compare_vectors(int v[], int t[], int n, int i){ 14 | if(i==n-1){ 15 | if(v[i]==t[i]){ 16 | return 1; 17 | } 18 | else{ 19 | return 0; 20 | exit(-1); 21 | } 22 | } 23 | else{ 24 | if(v[i]==t[i]){ 25 | i++; 26 | return compare_vectors(v, t, n, i); 27 | } 28 | else{ 29 | return 0; 30 | exit(-1); 31 | } 32 | } 33 | return 1; 34 | 35 | } 36 | 37 | 38 | int main(){ 39 | int v[]={1,2,4}; 40 | int t[]={1,2,4}; 41 | int n=3; 42 | int i=0; 43 | if(compare_vectors(v, t, n, i)==1){ 44 | printf("Vectors are equal\n"); 45 | } 46 | else{ 47 | printf("Vectors are not equal\n"); 48 | } 49 | 50 | return 0; 51 | } 52 | ``` 53 | -------------------------------------------------------------------------------- /Code/wildcard.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Navapallav Borthakur' 3 | Github: 'https://github.com/raj-hero' 4 | Problem: 'Wildcard Matching' 5 | Description: '? matches single char, * matches a sequence.' 6 | Explalnation: 'recursion+memoization- for ? we need to compare only 1 char each time, for * we need to compare a sequence. We first write the recursion, then memoize it.' 7 | Language: 'cpp' 8 | --- 9 | ```cpp 10 | 11 | class Solution { 12 | public: 13 | // helper function 14 | bool fun(int i,int j,string &p,string &s,vector>&dp) 15 | { 16 | // base cases 17 | if(i<0&&j<0) 18 | return true; 19 | else if(i<0&&j>=0) 20 | return false; 21 | else if(j<0&&i>=0) 22 | { 23 | for(int k=0;k<=i;++k){ 24 | if(p[k]!='*') 25 | return false; 26 | } 27 | return true; 28 | } 29 | else if(dp[i][j]!=-1) 30 | return dp[i][j]; 31 | // recursive calls 32 | else if(p[i]==s[j]||p[i]=='?') 33 | return dp[i][j]=fun(i-1,j-1,p,s,dp); 34 | else if(p[i]=='*'){ 35 | return dp[i][j]=(fun(i-1,j,p,s,dp)||fun(i,j-1,p,s,dp)); 36 | } 37 | return false; 38 | } 39 | bool isMatch(string s, string p) { 40 | int n=p.size(),m=s.size(); 41 | // for memoization 42 | vector>dp(n,vector(m,-1)); 43 | return fun(n-1,m-1,p,s,dp); 44 | } 45 | }; 46 | ``` 47 | -------------------------------------------------------------------------------- /Code/winnerOfCircularGame.md: -------------------------------------------------------------------------------- 1 | --- 2 | Name: 'Raj Anand' 3 | Github: 'https://github.com/raazanand' 4 | WebSite: '' 5 | Problem: 'Find the Winner of the Circular Game' 6 | Description: 'There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend. 7 | 8 | The rules of the game are as follows: 9 | 10 | 1. Start at the 1st friend. 11 | 2. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once. 12 | 3. The last friend you counted leaves the circle and loses the game. 13 | 4. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat. 14 | 5. Else, the last friend in the circle wins the game. 15 | Given the number of friends, n, and an integer k, return the winner of the game.' 16 | Language: 'Java' 17 | --- 18 | 19 | ```java 20 | 21 | import java.util.*; 22 | 23 | class Solution { 24 | public static void main(String[] args) { 25 | Scanner sc = new Scanner(System.in); 26 | System.out.println("Enter number of friend"); 27 | int n = sc.nextInt(); 28 | System.out.println("Enter value of k"); 29 | int k = sc.nextInt(); 30 | int ans = findTheWinner(n,k); 31 | System.out.println("winner of the game is: "+ans); 32 | } 33 | 34 | public int findTheWinner(int n, int k) { 35 | List list = new ArrayList<>(); 36 | for(int i=0;i list) { 44 | if(list.size()==1) { 45 | return; 46 | } 47 | index=(index+k)%list.size(); 48 | list.remove(index); 49 | solve(index,k,list); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recursion Hub 2 | 3 | Collections of solutions to **recursive problems**. You don't need to write an optimal solution, just write code with the help of recursion. 4 | 5 | ## Ways To Contribute 6 | 7 | There are two main contributions you can make. 8 | 9 | 1. The first is you can edit and improve the website node app. 10 | 2. The second way is to write any problem and solution in recursion, just make sure the problem is not yet written. 11 | 12 | ## Setup Node App(If you intend to do the first contribution option 1.) 13 | 14 | 1. Install Node.js and npm. 15 | 2. After cloning the app, go to the root folder and run the command below: 16 | 17 | ```bash 18 | npm i 19 | ``` 20 | 21 | 3. Then start the app 22 | 23 | ```bash 24 | node server.js 25 | 26 | or 27 | 28 | nodemon server.js 29 | ``` 30 | 31 | ## How to Contribute? 32 | 33 | ###### 1. Fork and clone this repository. 34 | 35 | ###### 2. Create a new branch with your name ([Find more details](https://github.com/firstcontributions/first-contributions)) 36 | 37 | ###### 3. Select any problem which can be solved by recursion. Please choose the problem which has not yet been taken or written. You can see on the website of this repo and check if the problem is written or not. And If after this you aren't able to find that problem is written or taken then create a new issue with **newproblem** tag. 38 | 39 | ###### 4. Select any programing language of your choice(Make Change in **_./Code_** folder only). and write code to solve the problem(Make sure the file name explains the problem in brief). Here you have to create one Markdown file for code. 40 | 41 | **MarkDown File Formate** 42 | 43 | 1. Contributor Introduction And Problem Information 44 | 45 | ```md 46 | --- 47 | Name: "Your Ans" 48 | Github: "Your Ans" 49 | WebSite: "Your Ans" 50 | Problem: "Your Ans" 51 | Description: "Your Ans" 52 | Language: "Your Ans" 53 | --- 54 | ``` 55 | 56 | Node: Website Part is optional. don't include Website key if you don't have website :). 57 | 58 | Please, follow this format only. 59 | 60 | - be make sure you have space right 61 | 62 | - This is not valid 63 | 64 | ```md 65 | Name:'Your Ans' 66 | 67 | or 68 | 69 | Name: Your Ans 70 | ``` 71 | 72 | - This is Valid 73 | ```md 74 | Name: 'Your Ans' 75 | ``` 76 | 77 | 2. Your Code 78 | Write code in this md format. Try to add problem explanation in comment in your code. See demo code. 79 |
80 | 81 | 82 | [Md File Demo](./Code/FibonacciNumber.md) 83 | 84 | ## Rules 85 | 86 | 1. Try to add some value and don't spam 87 | 2. Just follow the instructions given above and you are good to go. 88 | 89 | ## Contributors 90 | 91 | 92 | 93 | 98 | 99 |
94 | 95 | 96 | 97 |
100 | 101 | ## Thank You! 102 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Recursion Hub 9 | 10 | 11 | 13 | 14 | 15 | 64 | 65 | 66 | 78 |

Count of Programs: 0

79 |
80 |
81 | 103 |
104 | 105 | 106 | Back to Top 108 | 109 | 110 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /other/Bit operation/basicoperations: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/Bit operation/basicoperations -------------------------------------------------------------------------------- /other/Bit operation/basicoperations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int a=4; 5 | int b=6; 6 | cout<<"a&b = "<<(a&b)<>n; 8 | if((n&1) == 1){ 9 | cout<<"Odd Number"< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cout<<"Enter the Value of N ::\n"; 6 | cin>>n; 7 | for(int i=1;i<=n;i++){ 8 | cout< 2 | using namespace std; 3 | int main(){ 4 | int a=17; 5 | int b=a>>2; 6 | int c=19; 7 | int d=21<<2; 8 | a=a>>1; 9 | c=c<<1; 10 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cout<<"enter the N ::\n"; 6 | cin>>n; 7 | int sum =0; 8 | for(int i=1;i<=n;i++){ 9 | sum+=i; 10 | 11 | } 12 | 13 | cout<<"The Sum is :: "< 2 | using namespace std; 3 | int binarySearch(int arr[],int s,int e,int key){ 4 | if(s>e) return -1; 5 | int mid=s+(e-s)/2; 6 | if(arr[mid]==key)return mid; 7 | if(arr[mid] 2 | using namespace std; 3 | bool checkPalindrome(string s ,int i,int j){ 4 | if(i>j){ 5 | return true; 6 | } 7 | if(s[i]!=s[j]){ 8 | return false; 9 | } 10 | else{ 11 | return checkPalindrome(s,i+1,j-1); 12 | } 13 | 14 | 15 | 16 | 17 | } 18 | int main() 19 | { 20 | string name="abbccbba"; 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | // int a,b,c; 6 | // cout<<"Enter the value of a\n"; 7 | // cin>>a; 8 | // cout<<"Enter the value of b\n"; 9 | // cin>>b; 10 | // cout<<"Number Before swaping are "< 2 | using namespace std; 3 | void bubbleSort(int *arr,int n){ 4 | if(n==0 ||n==1){ 5 | return ; 6 | } 7 | 8 | for(int i=0;iarr[i+1]){ 10 | swap(arr[i],arr[i+1]); 11 | } 12 | } 13 | bubbleSort(arr,n-1); 14 | } 15 | int main() 16 | { 17 | int n=5; 18 | int arr[5]={2,3,1,5,0}; 19 | bubbleSort(arr,n); 20 | for(int i=0;i 2 | using namespace std; 3 | void merge(int *arr,int s,int e){ 4 | int mid=s+(e-s)/2; 5 | int len1=mid-s+1; 6 | int len2=e-mid; 7 | 8 | int *first=new int[len1]; 9 | int *second=new int[len2]; 10 | 11 | //copying values of array in array 12 | 13 | int mainArrayIndex=s; 14 | for(int i=0;i=e){ 56 | return ; 57 | } 58 | // cout<<"Hi "; 59 | //left part sort 60 | // int mid=s+(e-s)/2; 61 | int mid =s+(e-s)/2; 62 | mergeSort(arr,s,mid); 63 | //right part sort 64 | mergeSort(arr,mid+1,e); 65 | merge(arr,s,e); 66 | 67 | } 68 | int main() 69 | { 70 | int n=5; 71 | int arr[5]={8,5,1,6,9}; 72 | mergeSort(arr,0,n-1); 73 | for(int i=0;i 2 | using namespace std; 3 | int power(int a,int b){ 4 | if(b==0){ 5 | return 1; 6 | } 7 | if(b==1){ 8 | return a; 9 | } 10 | int ans=power(a,b/2); 11 | if(b%2==0){ 12 | return ans*ans; 13 | } 14 | else{ 15 | return a*ans*ans; 16 | } 17 | } 18 | int main() 19 | { 20 | int a,b; 21 | cout<<"enter a ::\n"; 22 | cin>>a; 23 | cout<<"enter b ::\n"; 24 | cin>>b; 25 | int ans=power(a,b); 26 | cout<<"a Power b is :: "< 4 | using namespace std; 5 | int partition(int *arr,int s ,int e){ 6 | int pivot=arr[s]; 7 | int cnt=0; 8 | for(int i=s+1;i<=e;i++){ 9 | if(arr[i]<=pivot){ 10 | cnt++; 11 | } 12 | } 13 | int pivotIndex=s+cnt; 14 | swap(arr[pivotIndex],arr[s]); 15 | 16 | //left or right wala part 17 | int i=s; 18 | int j=e; 19 | while(ipivotIndex){ 20 | while(arr[i]<=pivot){ 21 | i++; 22 | } 23 | while(arr[j]>pivot){ 24 | j--; 25 | } 26 | if(ipivotIndex){ 27 | swap(arr[i],arr[j]); 28 | } 29 | } 30 | return pivotIndex; 31 | } 32 | void quickSort(int *arr,int s,int e){ 33 | if(s>=e){ 34 | return ; 35 | } 36 | int p= partition(arr,s,e); 37 | //left part ke leye 38 | quickSort(arr,s,p-1); 39 | //Right part ke leye 40 | quickSort(arr,p+1,e); 41 | 42 | 43 | } 44 | int main() 45 | { 46 | int arr[6]={3,1,2,4,5,0}; 47 | int n=6; 48 | quickSort(arr,0,n-1); 49 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool isSafe(int x, int y, int n, vector > visited, vector > &m) 5 | { 6 | if ((x >= 0 && x < n) && (y >= 0 && y < n) && visited[x][y] == 0 && m[x][y] == 1) 7 | { 8 | 9 | return true; 10 | } 11 | else 12 | { 13 | return false; 14 | } 15 | } 16 | void solve(vector > &m, int n, vector &ans, int x, int y, vector > visited, 17 | string path) 18 | { 19 | if (x == n - 1 && y == n - 1) 20 | { 21 | ans.push_back(path); 22 | return; 23 | } 24 | visited[x][y] = 1; 25 | // 4 choices D L R U 26 | 27 | // down 28 | int newx = x + 1; 29 | int newy = y; 30 | if (isSafe(newx, newy, n, visited, m)) 31 | { 32 | path.push_back('D'); 33 | solve(m, n, ans, newx, newy, visited, path); 34 | path.pop_back(); 35 | } 36 | // left 37 | newx = x; 38 | newy = y - 1; 39 | if (isSafe(newx, newy, n, visited, m)) 40 | { 41 | path.push_back('L'); 42 | solve(m, n, ans, newx, newy, visited, path); 43 | path.pop_back(); 44 | } 45 | 46 | // right 47 | newx = x; 48 | newy = y + 1; 49 | if (isSafe(newx, newy, n, visited, m)) 50 | { 51 | path.push_back('R'); 52 | solve(m, n, ans, newx, newy, visited, path); 53 | path.pop_back(); 54 | } 55 | // up 56 | newx = x - 1; 57 | newy = y; 58 | if (isSafe(newx, newy, n, visited, m)) 59 | { 60 | path.push_back('U'); 61 | solve(m, n, ans, newx, newy, visited, path); 62 | path.pop_back(); 63 | } 64 | 65 | visited[x][y] = 0; 66 | } 67 | 68 | int main(){ 69 | vectorans; 70 | if(m[0][0]==0){ 71 | return ans; 72 | } 73 | 74 | int srcx=0; 75 | int srcy=0; 76 | vector >visited=m; 77 | //initializing with zero 78 | for(int i=0;i 2 | using namespace std; 3 | 4 | // void reverse(string &s,int i,int j){ 5 | // if(i>j) 6 | // { 7 | // return ; 8 | // } 9 | // swap(s[i],s[j]); 10 | 11 | // reverse(s,i+1,j-1); 12 | // } 13 | 14 | // void reverseStr(string s){ 15 | // if(s.size()==0){ 16 | // return ; 17 | // } 18 | // reverseStr(s.substr(1)); 19 | // cout< 2 | using namespace std; 3 | int getSum(int *arr,int n){ 4 | if(n==0){ 5 | return 0; 6 | } 7 | if(n==1){ 8 | return arr[0]; 9 | } 10 | int sum=arr[0]+getSum(arr+1,n-1); 11 | return sum; 12 | 13 | } 14 | int main() 15 | { 16 | int arr[5]={1,2,3,4,5}; 17 | int n=5; 18 | int ans=getSum(arr,n); 19 | cout< 2 | using namespace std; 3 | bool isSorted(int *arr,int n){ 4 | if(n==0 || n==1){ 5 | return true; 6 | } 7 | if(arr[0]>arr[1]){ 8 | return false; 9 | } 10 | return isSorted(arr+1,n-1); 11 | 12 | } 13 | int main() 14 | { 15 | int n=6; 16 | int arr[6]={2,9,6,9,11,13}; 17 | 18 | bool ans= isSorted(arr,n); 19 | if(ans){ 20 | cout<<"Array is Sorted"< 2 | using namespace std; 3 | int factorial(int n){ 4 | //Base Case 5 | if(n==0){ 6 | return 1; 7 | } 8 | // int smallerProblem=factorial(n-1); 9 | // int bigerProblem=n*smallerProblem; 10 | // return bigerProblem; 11 | 12 | return n* factorial(n-1); 13 | } 14 | int main() 15 | { 16 | int n; 17 | cout<<"Enter the n :: \n"; 18 | cin>>n; 19 | int ans=factorial(n); 20 | cout<<"Factorial is :: "< 2 | using namespace std; 3 | int search(int *arr,int s,int e,int key){ 4 | if(s>e){ 5 | return false; 6 | } 7 | int mid=s+(e-s)/2; 8 | if(arr[mid]==key) return mid; 9 | 10 | return search(arr,s+1,e,key); 11 | } 12 | int main() 13 | { 14 | int n=5; 15 | int arr[5]={1,2,3,4,5}; 16 | int key=4; 17 | int ans=search(arr,0,n-1,key); 18 | cout< 2 | using namespace std; 3 | void converter(int n ,string arr[]) 4 | { 5 | 6 | if(n==0){ 7 | cout<<"Zero"<<" "; 8 | return ; 9 | } 10 | 11 | int digit=n%10; 12 | n=n/10; 13 | 14 | converter(n,arr); 15 | cout<>n; 25 | string arr[10]={"Zero","one","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; 26 | 27 | 28 | 29 | converter(n,arr); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /other/Recursion/powof2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/Recursion/powof2 -------------------------------------------------------------------------------- /other/Recursion/powof2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int poweroftwo(int n){ 4 | // Base case 5 | if(n==0){ 6 | return 1; 7 | } 8 | // rescursive function 9 | 10 | return 2 * poweroftwo(n-1); 11 | 12 | } 13 | int main() 14 | { 15 | int n; 16 | cout<<"Enter the value of n :: \n"; 17 | cin>>n; 18 | int ans=poweroftwo(n); 19 | cout< 2 | using namespace std; 3 | void deccount(int n){ 4 | //Tail Recursion 5 | if(n==0) 6 | { 7 | return ; 8 | } 9 | cout<>n; 27 | 28 | deccount(n); 29 | cout<<"Incresing count is "< 2 | using namespace std; count(int n){ 3 | if(n==0) 4 | { 5 | return ; 6 | } 7 | cout<>n; 15 | int ans=count(n); 16 | cout< 2 | using namespace std; 3 | void reachHome(int src,int des){ 4 | 5 | cout<<"Source "< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | vectorv; 7 | v.push_back(1); 8 | v.push_back(2); 9 | v.push_back(3); 10 | v.push_back(4); 11 | v.push_back(5); 12 | v.push_back(6); 13 | v.push_back(7); 14 | 15 | cout<<"Finding the Number 6 "< 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | array a = {1, 2, 3, 4}; // int array with 4 size; 8 | // dyanamic array arraya; 9 | 10 | int size = a.size(); 11 | for (int i = 0; i < size; i++) 12 | { 13 | cout << a[i] << endl; 14 | } 15 | cout << "Element at 2nd Index is " << a.at(2) << endl; 16 | cout << "Array is Empty or not :: " << a.empty() << endl; 17 | cout << "First element is :: " << a.front() << endl; 18 | cout << "Last element is :: " << a.back() << endl; 19 | } -------------------------------------------------------------------------------- /other/STL/List: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/STL/List -------------------------------------------------------------------------------- /other/STL/List.cpp: -------------------------------------------------------------------------------- 1 | // List is implemented using Double Linked List(front pointer and back pointer ) we can not access is not possible using at krke ni nikal skte h and hume triverse krke pahuchna hoga wha 2 | // jumesa sbki time complexity O(1) hogi but erase ki O(n) 3 | #include 4 | // #include 5 | using namespace std; 6 | int main() 7 | { 8 | list l; 9 | // list n(l); 10 | list n(5, 100); 11 | for (int i : n) 12 | { 13 | cout << i << " "; 14 | } 15 | cout << endl; 16 | l.push_back(1); 17 | l.push_front(2); 18 | for (int i : l) 19 | { 20 | cout << i << " "; 21 | } 22 | cout << "After erase is :: " << endl; 23 | l.erase(l.begin()); 24 | for (int i : l) 25 | { 26 | cout << i << " "; 27 | } 28 | cout << "Size of list is " << l.size(); 29 | } -------------------------------------------------------------------------------- /other/STL/deque: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/STL/deque -------------------------------------------------------------------------------- /other/STL/deque.cpp: -------------------------------------------------------------------------------- 1 | // double ended queue insertion and deletion can perform at both side 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | deque d; 8 | d.push_back(1); 9 | d.push_back(5); 10 | d.push_front(2); 11 | d.push_front(3); 12 | // for (int i = 0; i < d.size(); i++) 13 | // { 14 | // cout << d[i] << " "; 15 | // } 16 | for (int i : d) 17 | { 18 | cout << i << " "; 19 | } 20 | // d.pop_back(); 21 | cout << endl; 22 | // for (int i : d) 23 | // { 24 | // cout << i << " "; 25 | // } 26 | cout << "First element at index 1 is ::" << d.at(1) << endl; 27 | cout << "Front :: " << d.front() << endl; 28 | cout << "Back :: " << d.back() << endl; 29 | cout << "Empty or not :: " << d.empty() << endl; 30 | cout << "Before erase Size :: " << d.size() << endl; 31 | // d.clear(); 32 | // cout << "Before erase Size :: " << d.size() << endl; 33 | d.erase(d.begin(), d.begin() + 1); 34 | cout << "After erase Size :: " << d.size() << endl; 35 | 36 | for (int i : d) 37 | { 38 | cout << i << " "; 39 | } 40 | 41 | // cout << "Before erase Capacity :: " << d.capacity() << endl; 42 | } -------------------------------------------------------------------------------- /other/STL/map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/STL/map -------------------------------------------------------------------------------- /other/STL/map.cpp: -------------------------------------------------------------------------------- 1 | //data will be store in form of key value and all key are unique and all are in sorted form 2 | //complecity of map in case of insert ,erase and all O(logn) 3 | #include 4 | // #include 5 | using namespace std; 6 | int main() 7 | { 8 | 9 | mapm;// ordered map 10 | m[1]="Ayush"; 11 | m[13]="SDE"; 12 | m[2]="Yadav"; 13 | //another way of insert 14 | // m.insert({5,"Chandan"}); 15 | // m.insert({4,"Ayush"}); 16 | cout<<"Before erase\n"; 17 | for(auto i:m){ 18 | cout<"< 4 | using namespace std; 5 | int main() 6 | { 7 | priority_queue max; // It is a Max Heap way to create a priority queue when we remove a element it will always remove max element in full queue 8 | 9 | priority_queue, greater > min; // way of creation of Min Heap 10 | //for Maximum heap 11 | max.push(1); 12 | max.push(2); 13 | max.push(3); 14 | max.push(0); 15 | cout<<"Size is :: "< 3 | using namespace std; 4 | int main() 5 | { 6 | 7 | queue q; 8 | q.push("Ayush"); 9 | q.push("Yadav"); 10 | q.push("SDE"); 11 | cout << "Front element is " << q.front(); 12 | cout << "Size befor pop is :: " << q.size() << endl; 13 | q.pop(); 14 | cout << endl; 15 | cout << "Front element is " << q.front() << endl; 16 | cout << "Size after pop is ::" << q.size() << endl; 17 | } -------------------------------------------------------------------------------- /other/STL/set: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/STL/set -------------------------------------------------------------------------------- /other/STL/set.cpp: -------------------------------------------------------------------------------- 1 | // always store Unique element 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | set s; 7 | s.insert(1); 8 | s.insert(1); 9 | s.insert(1); 10 | s.insert(2); 11 | s.insert(3); 12 | s.insert(4); 13 | // for(auto i : s){ 14 | // cout< :: iterator it=s.begin(); 20 | s.erase(it); 21 | // 22 | cout<<"Present or not "<:: iterator itr=s.find(4); 24 | for(auto it=itr;it!=s.begin();it++) 25 | { 26 | cout< 4 | using namespace std; 5 | int main() 6 | { 7 | stack s; 8 | s.push("Ayush"); 9 | s.push("Yadav"); 10 | s.push("SDE"); 11 | cout << "Front :: " << s.top(); 12 | s.pop(); 13 | cout << "Front :: " << s.top() << endl; 14 | ; 15 | cout << "Size of stack is ::" << s.size() << endl; 16 | cout << "Is empty stack or not " << s.empty() << endl; 17 | } -------------------------------------------------------------------------------- /other/STL/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | for(auto i : s){ 2 | // cout< 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | vector v; 9 | vector a(5, 1); // assign the element with size 5 and 1 other vice in defacult case it will assign with 0 10 | for (int i : a) 11 | { 12 | cout << i << " "; 13 | } 14 | // vector last(a); copy the element of a into last 15 | // v.push_back(1, 2, 3, 4, 5); 16 | // // int n = v.size(); 17 | // // for (int i = 0; i < n; i++) 18 | // // { 19 | // // cout << v[i] << endl; 20 | // // } 21 | cout << "Size is :: " << v.capacity() << endl; 22 | v.push_back(1); 23 | cout << "Size is :: " << v.capacity() << endl; 24 | v.push_back(2); 25 | cout << "Size is :: " << v.capacity() << endl; 26 | v.push_back(3); 27 | cout << "Size is :: " << v.capacity() << endl; 28 | cout << "size is :: " << v.size() << endl; 29 | cout << "ELement at 2nd Index is :: " << v.at(2) << endl; 30 | 31 | cout << "front element is ::" << v.front() << endl; 32 | cout << "last element is ::" << v.back() << endl; 33 | cout << "Before pop" << endl; 34 | for (int i : v) 35 | { 36 | cout << i << " "; 37 | } 38 | cout << endl; 39 | v.pop_back(); // remove from back 40 | cout << "After pop" << endl; 41 | for (int i : v) 42 | { 43 | cout << i << " "; 44 | } 45 | 46 | // clear operation me size zero hota h or capacity zero ni hoti kiu ki capacity assign ho chuki hoti h 47 | cout << "Array size is " << v.size() << endl; 48 | v.clear(); // clear the vector 49 | cout << "Array size is " << v.size() << endl; 50 | // begin operation 51 | } 52 | 53 | // vector is a dynamic array -------------------------------------------------------------------------------- /other/pointers/2DDynamicArray: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/pointers/2DDynamicArray -------------------------------------------------------------------------------- /other/pointers/2DDynamicArray.cpp: -------------------------------------------------------------------------------- 1 | /* Heap Ki memory agr use kr li hai toh hume usko clear ya free bhi krna hai or agr memory allocate kar di 2 | or usko free ni kra tb use memory leak kha jata h */ 3 | 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int row,col; 9 | cout<<"Enter Row :: \n"; 10 | cin>>row; 11 | cout<<"Enter the col :: \n"; 12 | cin>>col; 13 | 14 | int** arr=new int* [row]; 15 | //Creating Memory 16 | for(int i=0;i>arr[i][j]; 25 | } 26 | } 27 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cout<<"Enter the Vlue of n \n"<>n; 8 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int a=5; 6 | int *p=&a; 7 | int **q=&p; 8 | cout< 2 | using namespace std; 3 | 4 | void print(int *p){ 5 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | // char *ch=new char; 6 | // cout<<"Enter the Character"<>ch; 8 | // cout<>n; 14 | int* arr=new int[n]; 15 | for(int i=0;i>arr[i]; 18 | } 19 | 20 | for(int i=0;i 2 | using namespace std; 3 | void printArray(int arr[],int n,int start=0){ 4 | for(int i=start;i 2 | using namespace std; 3 | 4 | void func(int& a,int& b){ 5 | a++; 6 | b++; 7 | cout<b) ?a:b; 11 | } 12 | int main() 13 | { 14 | // func(5,6); 15 | int a=5; 16 | int b=6; 17 | // cout<<(a>b ?a:b); 18 | cout< 2 | // using namespace std; 3 | // #define pi 3.14 4 | // int main() 5 | // { 6 | // int n; 7 | // cout<<"Enter the value of radious"<>n; 9 | // // double pi=3.14; 10 | // double a=pi*n*n; 11 | // cout<<"Area is :: "< 17 | using namespace std; 18 | int Score =5; // Score is Defined globally we can use it anywhere 19 | 20 | // Macro definition 21 | #define INSTAGRAM FOLLOWERS 22 | #define FOLLOWERS 138 23 | 24 | // Driver Code 25 | int main() 26 | { 27 | // Print the message 28 | cout << "Geeks for Geeks have " 29 | << INSTAGRAM << "K followers on Instagram!"; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /other/pointers/macros/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | pi -------------------------------------------------------------------------------- /other/pointers/p2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/other/pointers/p2 -------------------------------------------------------------------------------- /other/pointers/p2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | // float f=10.5; 6 | // float p=2.5; 7 | // float *ptr=&f; 8 | // (*ptr)++; 9 | // *ptr=p; 10 | // cout<<*ptr<<" "< 2 | using namespace std; 3 | int main() 4 | { 5 | int num=6; 6 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | // int *p; bad practise of creating the address becaue it contain the garbege value 6 | // int i=5; 7 | // int *ptr=&i; 8 | 9 | // int *p=0; 10 | // p=&i; 11 | // cout<<"Address of ptr is :: "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // int arr[10]={1}; 7 | // cout<<"Address of First memory block is :: "< 2 | using namespace std; 3 | void update1(int n){ 4 | n++; 5 | } 6 | void update2(int &n){ 7 | n++; 8 | } 9 | 10 | int& func(int a){ 11 | int num=10; 12 | int ans=# 13 | return ans; 14 | 15 | } 16 | int main() 17 | { 18 | // int i=5; 19 | // int &j=i; 20 | // cout<<"Value of i is "<>n; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursion-hub", 3 | "version": "1.0.0", 4 | "description": "Write the solution of any **recursive problem** in any language of your choice. You Don't Need to write an optimal solution just write code with help of Recursion.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/zeel-codder/Recursion-Hub.git" 13 | }, 14 | "author": "", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/zeel-codder/Recursion-Hub/issues" 18 | }, 19 | "homepage": "https://github.com/zeel-codder/Recursion-Hub#readme", 20 | "dependencies": { 21 | "dotenv": "^10.0.0", 22 | "ejs": "^3.1.6", 23 | "express": "^4.17.1", 24 | "fs": "^0.0.1-security", 25 | "gray-matter": "^4.0.3", 26 | "install": "^0.13.0", 27 | "nodemon": "^2.0.13", 28 | "pug": "^3.0.2" 29 | } 30 | } -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const app = express(); 3 | const fs = require("fs"); 4 | const matter = require("gray-matter"); 5 | // app.use(express.static('')) 6 | // app.use(express.urlencoded()) 7 | // app.engine('html', require('ejs').renderFile) 8 | // app.set('view engine', 'html'); 9 | app.use("/public", express.static(__dirname + "/static")); 10 | 11 | app.get("/", (req, res) => { 12 | res.sendFile(__dirname + "/index.html"); 13 | }); 14 | 15 | app.get("/list", async (req, res) => { 16 | try { 17 | const list = await GetList(); 18 | res.send(JSON.stringify(list)); 19 | } catch (error) { 20 | console.log("Error in GetList Function\n", error); 21 | } 22 | }); 23 | 24 | const port = process.env.PORT || 3000; 25 | 26 | app.listen(port, () => { 27 | console.log(`Example app listening at http://localhost:${port}`); 28 | }); 29 | 30 | function GetList() { 31 | let ct = 0; 32 | try { 33 | const list = []; 34 | let filesList = fs.readdirSync(__dirname + "/Code"); 35 | filesList.forEach((file) => { 36 | // console.log(__dirname + "/Code/" + file); 37 | const data = fs.readFileSync(__dirname + "/Code/" + file); 38 | const dataForm = matter(data); 39 | const toAdd = { data: dataForm.data, content: dataForm.content }; 40 | list.push(toAdd); 41 | ct++; 42 | }); 43 | return list; 44 | } catch (e) { 45 | console.log(e) 46 | console.log("Error in File No(0-based)", ct); 47 | } 48 | } 49 | 50 | 51 | module.exports = app; -------------------------------------------------------------------------------- /static/RCHUB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/static/RCHUB.png -------------------------------------------------------------------------------- /static/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/static/code.png -------------------------------------------------------------------------------- /static/js/index.js: -------------------------------------------------------------------------------- 1 | const Count = document.querySelector(".count"); 2 | const listData = document.querySelector(".container-list"); 3 | const Input = document.querySelector(".input"); 4 | let count = 0; 5 | let list = []; 6 | function fetch() { 7 | axios.get("/list").then((res) => { 8 | list = res.data; 9 | SetData(list); 10 | }); 11 | } 12 | 13 | function SetData(list) { 14 | if (!list) { 15 | if (count >= 10) return; 16 | count++; 17 | fetch(); 18 | return; 19 | } 20 | let ct = 0; 21 | const toadd = list 22 | .map((data, index) => { 23 | try { 24 | ct++; 25 | return ` 26 |
27 |

${data.data.Name}

28 |
29 | Github 30 | WebSite 31 |
32 |
Problem: ${data.data.Problem}
33 |
Description: ${data.data.Description}
34 |

35 | 42 |

43 |
44 |
45 |

${data.data.Language.toLowerCase()}

46 |
47 |                 
48 |                     ${data.content
49 |                       .split("```")[1]
50 |                       .substr(data.content.split("```")[1].indexOf("\n"))}
51 |                 
52 |             
53 |
54 |
55 |
56 |
57 | `; 58 | } catch (e) { 59 | console.log("Unable to load Problem #", ct); 60 | } 61 | }) 62 | .join(""); 63 | Count.innerHTML = ct; 64 | listData.innerHTML = toadd; 65 | } 66 | 67 | function SetList(e) { 68 | if (Input.value == "") return SetData(list); 69 | const q = new RegExp(Input.value, "gi"); 70 | const newlist = list.filter((data) => { 71 | try { 72 | return data.data.Name.match(q) || data.data.Problem.match(q); 73 | } catch (e) { 74 | return false; 75 | } 76 | }); 77 | SetData(newlist); 78 | } 79 | 80 | fetch(); 81 | -------------------------------------------------------------------------------- /static/top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/static/top.png -------------------------------------------------------------------------------- /static/top1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeel-codder/Recursion-Hub/ef93473d8726a42eeda30c881279041e8e626153/static/top1.jpg -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { "version": 2, "rewrites": [{ "source": "/(.*)", "destination": "/server.js" }] , "builds": [{ "src": "server.js", "use": "@now/node" }] } 2 | --------------------------------------------------------------------------------