├── BasicGitCommand.MD ├── Problems ├── Alternate_Approach │ ├── Josephus.cpp │ ├── LongestSubarrayLength.cpp │ ├── TOH.cpp │ ├── example.cpp │ ├── gcd.cpp │ ├── palindrome.cpp │ └── power.cpp ├── Fix_Bugs │ ├── Josephus.cpp │ ├── Missing_Numbers.cpp │ ├── Next_Element.cpp │ ├── Paired_Char.cpp │ ├── Register_Username.cpp │ └── Sorting.cpp ├── Optimize_solution │ ├── factorial.cpp │ ├── fibonacci.cpp │ ├── findNumber.cpp │ ├── minAndMax.cpp │ ├── noOfchars.cpp │ ├── reverseString.cpp │ └── sorting.cpp └── Solution │ ├── Ousetion_1.md │ ├── Question_2.md │ ├── Question_3.md │ ├── Question_4.md │ ├── Question_5.md │ ├── Question_6.md │ ├── Question_7.md │ └── example.md ├── README.md ├── Students ├── LCB2023030 │ └── Solution │ │ └── Question_3.md.cpp ├── LCB2023032 │ └── Fix_Bugs │ │ ├── Register_Username.cpp │ │ └── Sorting.cpp ├── LCI2021023 │ └── Solution │ │ ├── example │ │ └── example.cpp ├── LCI2023010 │ └── Alternate_Approach │ │ └── gcd.cpp ├── LCI2023012 │ └── Optimize_solution │ │ └── sorting.cpp ├── LCI2023025 │ ├── Fix_Bugs │ │ ├── Josephus.cpp │ │ └── Next_Element.cpp │ └── Solution │ │ └── Question_1.cpp ├── LCI2023026 │ └── Solution │ │ ├── Question_2 │ │ └── Question_2.cpp ├── LCI2023038 │ ├── Alternate_Solution │ │ ├── Josephus.cpp │ │ └── power.cpp │ ├── FIx_Bugs │ │ └── Missing_Numbers.cpp │ └── Solution │ │ └── Question_6.cpp ├── LCS2022014 │ └── solution │ │ └── example.cpp ├── LCS2023030 ├── LIT2023002 │ └── Alternate_Approach │ │ └── factorial_recurssion.cpp ├── LIT2023022 │ ├── Alternate_approach │ │ └── LongestSubarrayLength.cpp │ ├── Fix_Bugs │ │ └── Paired_Char.cpp │ └── solution │ │ └── Question_7.cpp ├── LIT2023044 │ └── Optimize_solution │ │ └── fibonacci.cpp ├── lci2023032 │ ├── palindrome.cpp │ └── palindrome.exe ├── lcs2022049 │ └── helloworld.cpp ├── lit2023011 │ ├── Alternate_approach │ │ └── TOH_alt.cpp │ └── solution │ │ └── Question_4.cpp └── readme.md └── issue_template.md /BasicGitCommand.MD: -------------------------------------------------------------------------------- 1 | 2 | # Git Commands Cheatsheet 3 | 4 | ## Git Clone 5 | Before cloning the repository ,you need to fork it first 6 | Creates a local copy of a remote repository. 7 | 8 | 9 | `git clone ` 10 | 11 | 12 | ## Git Checkout -b 13 | Creates a new branch and switches to it. 14 | 15 | 16 | `git checkout -b ` 17 | 18 | 19 | ## Git Branch 20 | Lists all branches in the repository. 21 | 22 | 23 | `git branch` 24 | 25 | 26 | ## Git Checkout 27 | Switches to the specified branch. 28 | 29 | 30 | `git checkout ` 31 | 32 | 33 | ## Git Status 34 | Displays the current status of the working directory. 35 | 36 | 37 | `git status` 38 | 39 | 40 | ## Git Add 41 | Stages a specific file for the next commit. 42 | 43 | 44 | `git add ` 45 | 46 | 47 | ## Git Add . 48 | Stages all modified files in the working directory for the next commit. 49 | 50 | 51 | `git add .` 52 | 53 | 54 | ## Git Commit -m 55 | Records changes to the repository with a commit message. 56 | 57 | 58 | `git commit -m ""` 59 | 60 | 61 | ## Git Push --set-upstream 62 | Pushes the local branch to the remote repository and sets the upstream branch. 63 | 64 | 65 | `git push --set-upstream origin ` 66 | 67 | 68 | ## Git Log 69 | Displays a log of commits. 70 | 71 | 72 | `git log` 73 | 74 | # Some resources to learn about git and git commands 75 | [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
76 | [Common git commands](https://www.youtube.com/watch?v=xnR0dlOqNVE)
77 | [Complete Git and Github Course](https://www.youtube.com/watch?v=jhucqYjk3XM)
78 | 79 | -------------------------------------------------------------------------------- /Problems/Alternate_Approach/Josephus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int Josephus(int N, int k) 5 | { 6 | int i = 1, ans = 0; 7 | 8 | while (i <= N) { 9 | ans = (ans + k) % i; 10 | i++; 11 | } 12 | 13 | return ans + 1; 14 | } 15 | 16 | int main() 17 | { 18 | int N, k; 19 | cin >> N >> k; 20 | 21 | cout << Josephus(N, k) << endl; 22 | return 0; 23 | } 24 | // Provide another approach to above josephus problem. 25 | // Hint use Recursive 26 | -------------------------------------------------------------------------------- /Problems/Alternate_Approach/LongestSubarrayLength.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int longestSubarrayLength(int arr[], int n, int k) { 4 | int maxLength = 0; 5 | 6 | for (int start = 0; start < n; ++start) { 7 | int sum = 0; 8 | for (int end = start; end < n; ++end) { 9 | sum += arr[end]; 10 | if (sum <= k) { 11 | int subarrayLength = end - start + 1; 12 | maxLength = std::max(maxLength, subarrayLength); 13 | } else { 14 | break; // The sum exceeds k, no need to continue this subarray 15 | } 16 | } 17 | } 18 | 19 | return maxLength; 20 | } 21 | 22 | int main() { 23 | int n, k; 24 | 25 | std::cout << "Enter the size of the array: "; 26 | std::cin >> n; 27 | 28 | int arr[n]; 29 | std::cout << "Enter the elements of the array:\n"; 30 | for (int i = 0; i < n; ++i) { 31 | std::cin >> arr[i]; 32 | } 33 | 34 | std::cout << "Enter the value of k: "; 35 | std::cin >> k; 36 | 37 | int result = longestSubarrayLength(arr, n, k); 38 | std::cout << "Length of the longest subarray with sum less than or equal to " << k << " is: " << result << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Problems/Alternate_Approach/TOH.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void TowerOfHanoi(int num_disks) { 5 | stack source, auxiliary, destination; 6 | int total_moves = (1 << num_disks) - 1; 7 | for (int i = num_disks; i >= 1; i--) { 8 | source.push(i); 9 | } 10 | 11 | char A = 'A', B = 'B', C = 'C'; 12 | 13 | if (num_disks % 2 == 0) { 14 | swap(auxiliary, destination); 15 | swap(B, C); 16 | } 17 | 18 | for (int move = 1; move <= total_moves; move++) { 19 | if (move % 3 == 1) { 20 | if (!source.empty() && (destination.empty() || source.top() < destination.top())) { 21 | cout << "Move disk " << source.top() << " from " << A << " to " << C << endl; 22 | destination.push(source.top()); 23 | source.pop(); 24 | } else if (!destination.empty() && (source.empty() || destination.top() < source.top())) { 25 | cout << "Move disk " << destination.top() << " from " << C << " to " << A << endl; 26 | source.push(destination.top()); 27 | destination.pop(); 28 | } 29 | } else if (move % 3 == 2) { 30 | if (!source.empty() && (auxiliary.empty() || source.top() < auxiliary.top())) { 31 | cout << "Move disk " << source.top() << " from " << A << " to " << B << endl; 32 | auxiliary.push(source.top()); 33 | source.pop(); 34 | } else if (!auxiliary.empty() && (source.empty() || auxiliary.top() < source.top())) { 35 | cout << "Move disk " << auxiliary.top() << " from " << B << " to " << A << endl; 36 | source.push(auxiliary.top()); 37 | auxiliary.pop(); 38 | } 39 | } else if (move % 3 == 0) { 40 | if (!auxiliary.empty() && (destination.empty() || auxiliary.top() < destination.top())) { 41 | cout << "Move disk " << auxiliary.top() << " from " << B << " to " << C << endl; 42 | destination.push(auxiliary.top()); 43 | auxiliary.pop(); 44 | } else if (!destination.empty() && (auxiliary.empty() || destination.top() < auxiliary.top())) { 45 | cout << "Move disk " << destination.top() << " from " << C << " to " << B << endl; 46 | auxiliary.push(destination.top()); 47 | destination.pop(); 48 | } 49 | } 50 | } 51 | } 52 | 53 | int main() { 54 | int num_disks; 55 | cout << "Enter the number of disks: "; 56 | cin >> num_disks; 57 | TowerOfHanoi(num_disks); 58 | return 0; 59 | } 60 | 61 | 62 | // Provide an another approach to solve the above question 63 | // (Do you want a hint?). -------------------------------------------------------------------------------- /Problems/Alternate_Approach/example.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSC-IIITL/GitGrind/23ec2a4d9fe0a199f2dd0f47bf21f869e695f09c/Problems/Alternate_Approach/example.cpp -------------------------------------------------------------------------------- /Problems/Alternate_Approach/gcd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int GCD(int a, int b) { 5 | if (b == 0) { 6 | return a; 7 | } else { 8 | return GCD(b, a % b); 9 | } 10 | } 11 | 12 | int main() { 13 | int num1, num2; 14 | cin >> num1 >> num2; 15 | int gcd = GCD(num1, num2); 16 | cout << "GCD: " << gcd << endl; 17 | return 0; 18 | } 19 | 20 | // Provide an another approach to solve the above question 21 | // (Do you want a hint?). -------------------------------------------------------------------------------- /Problems/Alternate_Approach/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isPalindrome(string str, int left, int right) { 5 | if (left >= right) { 6 | return true; 7 | } else if (str[left] != str[right]) { 8 | return false; 9 | } else { 10 | return isPalindrome(str, left + 1, right - 1); 11 | } 12 | } 13 | 14 | int main() { 15 | string str; 16 | cout << "Enter a string: "; 17 | cin >> str; 18 | 19 | if (isPalindrome(str, 0, str.length() - 1)) { 20 | cout << " Palindrome." << endl; 21 | } else { 22 | cout << " Not a Palindrome." << endl; 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | // Provide an another approach to solve the above question 29 | // (Do you want a hint?). -------------------------------------------------------------------------------- /Problems/Alternate_Approach/power.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | double Power(double base, int exponent) { 5 | double result = 1.0; 6 | if (exponent < 0) { 7 | base = 1.0 / base; 8 | exponent = -exponent; 9 | } 10 | while (exponent > 0) { 11 | if (exponent % 2 == 1) { 12 | result *= base; 13 | } 14 | base *= base; 15 | exponent /= 2; 16 | } 17 | return result; 18 | } 19 | 20 | int main() { 21 | double base; 22 | int exponent; 23 | cin >> base; 24 | cin >> exponent; 25 | double result = Power(base, exponent); 26 | cout << "Result: " << result << endl; 27 | return 0; 28 | } 29 | 30 | // Provide an another/alternate approach to solve the above question 31 | // (Do you want a hint?). -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Josephus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int Josephus(int N, int k) 5 | { 6 | int i = 1, ans = 0; 7 | 8 | while (i <= N) { 9 | ans = (ans + k) % i; 10 | i++; 11 | } 12 | 13 | return ans; 14 | } 15 | 16 | int main() 17 | { 18 | int N, k; 19 | cin >> N >> k; 20 | cout << Josephus(N, k) << endl; 21 | return 0; 22 | } 23 | // This is josephus problem. It has few bugs!! Fix them. 24 | -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Missing_Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int findMissingNumber(vector& nums) { 5 | sort(nums.begin(), nums.end()); 6 | int n = nums.size(); 7 | for (int i = 1; i <= n; i++) { 8 | if (nums[i - 1] != i) { 9 | return i; 10 | } 11 | } 12 | return n; 13 | } 14 | 15 | int main() { 16 | int n; 17 | cin >> n; 18 | vector nums(n); 19 | for (int i = 0; i < n; i++) { 20 | cin >> nums[i]; 21 | } 22 | int missing_number = findMissingNumber(nums); 23 | cout << missing_number << endl; 24 | return 0; 25 | } 26 | 27 | // There are few Logical errors in the code. Fix them and submit the code. 28 | 29 | -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Next_Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | vector nextGreaterElements(vector& nums) { 6 | int n = nums.size(); 7 | nums.resize(2 * n); 8 | for (int i = n; i < 2 * n; i++) { 9 | nums[i] = nums[i - n]; 10 | } 11 | vector res(n); 12 | stack st; 13 | 14 | for (int i = n - 1; i >= 0; i--) { 15 | while (!st.empty() && nums[i] <= nums[st.top()]) { 16 | st.pop(); 17 | } 18 | int idx = i % n; 19 | res[idx] = st.empty() ? -1 : nums[st.top()]; 20 | st.push(i); 21 | } 22 | 23 | return res; 24 | } 25 | 26 | int main() { 27 | int n; 28 | cout << "Enter the number of elements in the circular array: "; 29 | cin >> n; 30 | 31 | vector nums(n); 32 | cout << "Enter the elements separated by spaces: "; 33 | for (int i = 0; i < n; i++) { 34 | cin >> nums[i]; 35 | } 36 | 37 | vector result = nextGreaterElements(nums); 38 | 39 | cout << "Next Greater Elements in Circular Array: "; 40 | for (int i = 0; i < n; i++) { 41 | cout << result[i] << " "; 42 | } 43 | cout << endl; 44 | 45 | return 0; 46 | } 47 | 48 | 49 | // There are few Logical errors in the code. Fix them and submit the code. -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Paired_Char.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int countPairedCharacters(int n, string s) { 5 | unordered_map d; 6 | int c = 0; 7 | 8 | for (int i = 1; i < 2 * n - 2; i += 2) { 9 | if (s[i] - 32 != s[i + 1]) { 10 | d[s[i]]++; 11 | if (d[s[i + 1] + 32] != 0) { 12 | d[s[i + 1] + 32]--; 13 | } else { 14 | c--; 15 | } 16 | } 17 | } 18 | 19 | return c; 20 | } 21 | 22 | int main() { 23 | int n; 24 | cin >> n; 25 | string s; 26 | cin >> s; 27 | 28 | int result = countPairedCharacters(n, s); 29 | 30 | cout << result << endl; 31 | 32 | return 0; 33 | } 34 | 35 | // There are few Logical errors in the code. Fix them and submit the code. -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Register_Username.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void registerUsernames(int n) 5 | { 6 | map database; 7 | 8 | for (int i = 0; i < n; i++) 9 | { 10 | string s; 11 | cin >> s; 12 | 13 | if (database.count(s) == 0) 14 | { 15 | cout << "OK" << endl; 16 | database[s] = 1; 17 | } 18 | else 19 | { 20 | while (true) 21 | { 22 | string newUsername = s + to_string(database[s]); 23 | if (database.count(s) == 0) 24 | { 25 | database.count(newUsername); 26 | cout<< newUsername << endl; 27 | database[newUsername] = 1; 28 | break; 29 | } 30 | database[s]++; 31 | } 32 | } 33 | } 34 | } 35 | 36 | int main() 37 | { 38 | int n; 39 | cout << "Enter the number of username registration attempts: "; 40 | cin >> n; 41 | registerUsernames(n); 42 | return 0; 43 | } 44 | 45 | // There are few Logical errors in the code. Fix them and submit the code. -------------------------------------------------------------------------------- /Problems/Fix_Bugs/Sorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const long long MOD = 1000000007; 6 | 7 | typedef long long ll; 8 | typedef long double ld; 9 | typedef pair pii; 10 | typedef pair pll; 11 | 12 | void merge(int start, int mid, int end, vector& arr, vector& A, vector& tmp, vector& tmp1) { 13 | int p = start; 14 | int q = mid; 15 | int r = p; 16 | 17 | while (p < mid && q <= end) { 18 | if (arr[p] >= arr[q]) { 19 | tmp1[r] = A[p]; 20 | tmp[r++] = arr[p++]; 21 | } else { 22 | tmp1[r] = A[q]; 23 | tmp[r++] = arr[q++]; 24 | } 25 | } 26 | 27 | while (p < mid) { 28 | tmp1[r] = A[p]; 29 | tmp[r++] = arr[p++]; 30 | } 31 | 32 | while (q <= end) { 33 | tmp1[r] = A[q]; 34 | tmp[r++] = arr[q++]; 35 | } 36 | 37 | for (p = start; p <= end; ++p) { 38 | arr[p] = tmp[p]; 39 | A[p] = tmp1[p]; 40 | } 41 | } 42 | 43 | void merge_sort(int l, int r, vector& arr, vector& A, vector& tmp, vector& tmp1) { 44 | if (l < r) { 45 | int mid = (l + r) >> 1; 46 | merge_sort(l, mid, arr, A, tmp, tmp1); 47 | merge_sort(mid + 1, r, arr, A, tmp, tmp1); 48 | merge(l, mid + 1, r, arr, A, tmp, tmp1); 49 | } 50 | } 51 | 52 | int main() { 53 | 54 | ll n, i, x, y; 55 | cin >> n; 56 | x = 0; 57 | 58 | vector A(n), arr(n), tmp(n), tmp1(n); 59 | 60 | for (i = 0; i < n; ++i) { 61 | cin >> A[i]; 62 | if (A[i] < x) x = A[i]; 63 | } 64 | 65 | y = 1; 66 | ll I = 1; 67 | 68 | while (x / I) { 69 | for (i = 0; i < n; ++i) { 70 | arr[i] = (A[i] / I) % 100000; 71 | } 72 | merge_sort(0, n - 1, arr, A, tmp, tmp1); 73 | 74 | for (i = 0; i < n; ++i) { 75 | cout << A[i] << " "; 76 | } 77 | cout << "\n"; 78 | I *= 100000; 79 | } 80 | 81 | return 0; 82 | } 83 | 84 | // There are few Logical errors in the code. Fix them and submit the code. -------------------------------------------------------------------------------- /Problems/Optimize_solution/factorial.cpp: -------------------------------------------------------------------------------- 1 | // Finding the factorial of the given number 2 | //! Hint: Try using recursive approach 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | long long num=1; 10 | for(int i=2;i<=n;i++){ 11 | num*=i; 12 | } 13 | cout< 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | int a=0,b=1,c=b; 10 | cout< 5 | using namespace std; 6 | 7 | int main(){ 8 | int n; 9 | cin>>n; 10 | int a[n]; 11 | for(int i=0;i>a[i]; 13 | } 14 | cout<<"Enter the element to be search in the given array: "; 15 | int x; 16 | cin>>x; 17 | for(int i=0;i 5 | using namespace std; 6 | 7 | int main(){ 8 | int n; 9 | cin>>n; 10 | int a[n]; 11 | for(int i=0;i>a[i]; 13 | } 14 | int min=INT_MAX; 15 | for(int i=0;ia[i]){ 17 | min=a[i]; 18 | } 19 | } 20 | int max=INT_MIN; 21 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | char c; 10 | cin>>c; 11 | int count=0; 12 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | 10 | cout<<"Initial String: "< 4 | using namespace std; 5 | 6 | void printArray(int a[],int n){ 7 | for(int i=0;i>n; 16 | int a[n]; 17 | for(int i=0;i>a[i]; 19 | } 20 | printArray(a,n); 21 | for(int i=0;ia[j]){ 24 | int temp=a[i]; 25 | a[i]=a[j]; 26 | a[j]=temp; 27 | } 28 | } 29 | } 30 | cout<<"Sorted array: "; 31 | printArray(a,n); 32 | } -------------------------------------------------------------------------------- /Problems/Solution/Ousetion_1.md: -------------------------------------------------------------------------------- 1 | # Strictly Increasing Array with One Removal 2 | 3 | ## Problem Statement 4 | 5 | Given a 0-indexed integer array `nums`, determine if it can be made strictly increasing after removing exactly one element. If the array is already strictly increasing, return true. 6 | 7 | The array `nums` is strictly increasing if `nums[i - 1] < nums[i]` for each index (`1 <= i < nums.length`). 8 | 9 | ### Examples 10 | 11 | #### Example 1: 12 | 13 | **Input:** 14 | nums = [1,2,10,5,7] 15 | 16 | **Output:** true 17 | 18 | **Explanation:** By removing 10 at index 2 from nums, it becomes [1,2,5,7]. 19 | [1,2,5,7] is strictly increasing, so return true. 20 | 21 | #### Example 2: 22 | 23 | **Input:** 24 | 25 | nums = [2,3,1,2] 26 | 27 | **Output:** false 28 | 29 | **Explanation:** [3,1,2] is the result of removing the element at index 0. 30 | [2,1,2] is the result of removing the element at index 1. 31 | [2,3,2] is the result of removing the element at index 2. 32 | [2,3,1] is the result of removing the element at index 3. 33 | 34 | No resulting array is strictly increasing, so return false. 35 | 36 | #### Example 3: 37 | 38 | **Input:** 39 | 40 | nums = [1,1,1] 41 | 42 | **Output:** false 43 | 44 | **Explanation:** The result of removing any element is [1,1]. 45 | [1,1] is not strictly increasing, so return false. 46 | 47 | ## Constraints 48 | 49 | - `2 <= nums.length <= 1000` 50 | - `1 <= nums[i] <= 1000` -------------------------------------------------------------------------------- /Problems/Solution/Question_2.md: -------------------------------------------------------------------------------- 1 | # Grass Cutting 2 | 3 | ## Problem Description 4 | 5 | You are given a field of size 2×2. Each cell of this field can either contain grass or be empty. The value \(a{i,j}\) is 1 if the cell \((i,j)\) contains grass, or 0 otherwise. In one move, you can choose one row and one column and cut all the grass in this row and this column. In other words, you choose the row \(x\) and the column \(y\), then you cut the grass in all cells \(a{x,i}\) and all cells \(a{i,y}\) for all \(i\) from 1 to 2. After you cut the grass from a cell, it becomes empty (i.e. its value is replaced by 0). 6 | 7 | Your task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i.e. make all \(a{i,j}\) zeros). 8 | 9 | ## Input 10 | 11 | The first line of the input contains one integer `t(1 <= t <= 16)` — the number of test cases. Then \(t\) test cases follow. 12 | 13 | The test case consists of two lines, each of these lines contains two integers. The \(j\)-th integer in the \(i\)-th row is \(a{i,j}\). If \(a{i,j} = 0\) then the cell \((i,j)\) is empty, and if \(a{i,j} = 1\) the cell \((i,j)\) contains grass. 14 | 15 | ## Output 16 | 17 | For each test case, print one integer - the minimum number of moves required to cut the grass in all non-empty cells of the field (i.e. make all \(a{i,j}\) zeros) in the corresponding test case. 18 | 19 | ## Example 20 | 21 | ### Input 22 | 23 | ``` 24 | 3 25 | 0 0 26 | 0 0 27 | 1 0 28 | 0 1 29 | 1 1 30 | 1 1 31 | ``` 32 | 33 | ### Output 34 | 35 | ``` 36 | 0 37 | 1 38 | 2 39 | ``` 40 | 41 | ## Constraints 42 | 43 | - \(1 <= t <= 16\) 44 | - \(a{i,j} ∈ \{0,1\}\) -------------------------------------------------------------------------------- /Problems/Solution/Question_3.md: -------------------------------------------------------------------------------- 1 | # Santa's Candy Dilemma 2 | 3 | ## Problem Description 4 | 5 | Santa has a certain number of candies and wants to gift them to a group of kids. He has specific conditions to satisfy while distributing the candies. Your task is to determine the maximum number of candies Santa can give to the kids while meeting these conditions. 6 | 7 | ## Input 8 | 9 | The first line of the input contains an integer `t` (1≤t≤5⋅10^4) — the number of test cases. 10 | 11 | The next `t` lines describe test cases. Each test case contains two integers `n` and `k` (1≤n,k≤10^9) — the number of candies and the number of kids. 12 | 13 | ## Output 14 | 15 | For each test case, print the answer — the maximum number of candies Santa can give to the kids while satisfying the given conditions. 16 | 17 | ## Example 18 | 19 | **Input:** 20 | 21 | ``` 22 | 5 23 | 5 2 24 | 19 4 25 | 12 7 26 | 6 2 27 | 100000 50010 28 | ``` 29 | 30 | 31 | **Output:** 32 | 33 | ``` 34 | 5 35 | 18 36 | 10 37 | 6 38 | 75015 39 | ``` 40 | 41 | ## Explanation 42 | 43 | - In the first test case, Santa can give 3 and 2 candies to kids. There a=2,b=3,a+1=3. 44 | - In the second test case, Santa can give 5,5,4, and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3. 45 | - In the third test case, Santa can distribute candies in the following way: [1,2,2,1,1,2,1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied. 46 | - In the fourth test case, Santa can distribute candies in the following way: [3,3]. There a=3,b=3,a+1=4. Santa distributed all 6 candies. 47 | 48 | ## Constraints 49 | 50 | - 1 ≤ t ≤ 5⋅10^4 51 | - 1 ≤ n, k ≤ 10^9 52 | -------------------------------------------------------------------------------- /Problems/Solution/Question_4.md: -------------------------------------------------------------------------------- 1 | # Third Distinct Maximum in an Integer Array 2 | 3 | Given an integer array `nums`, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number. 4 | 5 | ## Example 1: 6 | 7 | **Input:** 8 | 9 | ``` 10 | nums = [3,2,1] 11 | ``` 12 | 13 | **Output:** 1 14 | 15 | **Explanation:** 16 | - The first distinct maximum is **3**. 17 | - The second distinct maximum is **2**. 18 | - The third distinct maximum is **1**. 19 | 20 | ## Example 2: 21 | 22 | **Input:** 23 | 24 | ``` 25 | nums = [1,2] 26 | ``` 27 | 28 | **Output:** 2 29 | 30 | **Explanation:** 31 | - The first distinct maximum is **2**. 32 | - The second distinct maximum is **1**. 33 | - The third distinct maximum does not exist, so the maximum (**2**) is returned instead. 34 | 35 | ## Example 3: 36 | 37 | **Input:** 38 | 39 | ``` 40 | nums = [2,2,3,1] 41 | ``` 42 | 43 | **Output:** 1 44 | 45 | **Explanation:** 46 | - The first distinct maximum is **3**. 47 | - The second distinct maximum is **2**. (both 2's are counted together since they have the same value). 48 | - The third distinct maximum is **1**. 49 | 50 | ## Constraints 51 | 52 | - `1 <= nums.length <= 10^4` 53 | - `-2^31 <= nums[i] <= 2^31 - 1` 54 | -------------------------------------------------------------------------------- /Problems/Solution/Question_5.md: -------------------------------------------------------------------------------- 1 | # Splitting Ranges into Two Groups 2 | 3 | You are given a 2D integer array `ranges` where `ranges[i] = [starti, endi]` denotes that all integers between `starti` and `endi` (both inclusive) are contained in the ith range. 4 | 5 | You are to split ranges into two (possibly empty) groups such that: 6 | 7 | - Each range belongs to exactly one group. 8 | - Any two overlapping ranges must belong to the same group. 9 | - Two ranges are said to be overlapping if there exists at least one integer that is present in both ranges. 10 | 11 | ## Example 1 12 | 13 | **Input:** 14 | 15 | ``` 16 | ranges = [[6,10],[5,15]] 17 | ``` 18 | 19 | **Output:** 2 20 | 21 | **Explanation:** 22 | The two ranges are overlapping, so they must be in the same group. 23 | Thus, there are two possible ways: 24 | - Put both the ranges together in group 1. 25 | - Put both the ranges together in group 2. 26 | 27 | ## Example 2 28 | 29 | **Input:** 30 | 31 | ``` 32 | ranges = [[1,3],[10,20],[2,5],[4,8]] 33 | ``` 34 | 35 | **Output:** 4 36 | 37 | **Explanation:** 38 | Ranges [1,3], and [2,5] are overlapping. So, they must be in the same group. 39 | Again, ranges [2,5] and [4,8] are also overlapping. So, they must also be in the same group. 40 | Thus, there are four possible ways to group them: 41 | - All the ranges in group 1. 42 | - All the ranges in group 2. 43 | - Ranges [1,3], [2,5], and [4,8] in group 1 and [10,20] in group 2. 44 | - Ranges [1,3], [2,5], and [4,8] in group 2 and [10,20] in group 1. 45 | 46 | ## Constraints 47 | 48 | - 1 <= ranges.length <= 105 49 | - ranges[i].length == 2 50 | - 0 <= starti <= endi <= 109 51 | -------------------------------------------------------------------------------- /Problems/Solution/Question_6.md: -------------------------------------------------------------------------------- 1 | # Statement: 2 | 3 | You are given an array of integers. Write a function that returns the sum of all the even numbers in the array. 4 | 5 | **Input:** 6 | - An array of integers, `arr`. 7 | 8 | **Output:** 9 | - An integer representing the sum of all even numbers in the array. 10 | 11 | ### Example 1: 12 | 13 | **Input:** 14 | arr = [1, 2, 3, 4, 5, 6] 15 | 16 | **Output:** 17 | 12 18 | 19 | **Explanation:** 20 | In the given array, the even numbers are 2, 4, and 6. The sum of these even numbers is 12. 21 | 22 | ### Example 2: 23 | 24 | **Input:** 25 | arr = [10, 20, 30, 40, 50] 26 | 27 | 28 | **Output:** 29 | 150 30 | 31 | **Explanation:** 32 | In the given array, all the numbers are even. The sum of all even numbers is 150. 33 | 34 | -------------------------------------------------------------------------------- /Problems/Solution/Question_7.md: -------------------------------------------------------------------------------- 1 | # Statement: 2 | 3 | You are given a list of words. Write a function to find the word with the most anagrams in the list and return that word. 4 | 5 | **Input:** 6 | - A list of words, `word_list`, where 1 <= len(word_list) <= 1000. 7 | - Each word in the list is a string consisting of lowercase letters. 8 | 9 | **Output:** 10 | - A string representing the word with the most anagrams in the list. If there are multiple words with the same maximum number of anagrams, return any one of them. 11 | 12 | ### Example: 13 | 14 | **Input:** 15 | word_list = ["listen", "silent", "hello", "lovers", "siren"] 16 | 17 | **Output:** 18 | listen 19 | 20 | **Explanation:** 21 | In the given list, "listen" and "silent" are anagrams of each other. No other words in the list have anagrams. "listen" has the most anagrams, so it is the output. 22 | -------------------------------------------------------------------------------- /Problems/Solution/example.md: -------------------------------------------------------------------------------- 1 | # Array Sum Calculator 2 | 3 | ## Question 4 | 5 | Write a program that takes 10 values as input from the user, stores them in an array, calculates the sum of all the values in the array, and prints the sum. 6 | 7 | ## Examples 8 | 9 | ### Input 10 | 11 | ``` 12 | 5 10 15 20 25 30 35 40 45 50 13 | ``` 14 | 15 | ### Output 16 | 17 | Sum of the array elements: 275 18 | 19 | ## Constraints 20 | 21 | - The program should take exactly 10 input values. 22 | - The input values should be integers. 23 | - The values can be both positive and negative. 24 | - The program should print the sum of the array elements. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Contributing to GitGrind:CP Edition** 2 | 3 | Welcome to GitGrind:CP Edition! We're thrilled to have you contribute to our project. 4 | 5 | ## How to Contribute 6 | 7 | To contribute to GitGrind:CP Edition, please follow these steps: 8 | 9 | 1. **Fork the Repository:** 10 | 11 | - Click on the "Fork" button at the top right corner of this repository's page. This will create a copy of the repository in your GitHub account. 12 | 13 | 2. **Clone the Forked Repository:** 14 | 15 | ``` 16 | git clone https://github.com/YourUsername/GitGrind.git 17 | ``` 18 | 19 | Clone the forked repository to your local machine using the above command. Replace `YourUsername` with your GitHub username. 20 | 21 | 3. **Wait for Issue Assignment:** 22 | 23 | - Issues will be assigned to contributors in chronological order. 24 | - Please wait for your issue to be assigned before starting to work on it. 25 | 26 | 4. **Create a New Branch:** 27 | 28 | ``` 29 | git checkout -b YourRollNumber 30 | ``` 31 | 32 | Create a new branch for your contribution using the above command. Replace `YourRollNumber` with your actual roll number. 33 | 34 | 5. **Make Changes and Commit:** 35 | 36 | - Make your changes in the codebase. 37 | - Stage your changes: `git add .` 38 | - Commit your changes with a descriptive message: 39 | ``` 40 | git commit -m "Fix bugs in question X" 41 | ``` 42 | Replace the commit message with a clear and concise description of the changes you made. 43 | 44 | 6. **Push Changes to Your Branch:** 45 | 46 | ``` 47 | git push --set-upstream origin YourRollNumber 48 | ``` 49 | 50 | Push your changes to the branch you created on your forked repository. Replace `YourRollNumber` with your actual roll number. 51 | 52 | 7. **Create a Pull Request:** 53 | - Go to the original repository on GitHub. 54 | - Click on the "New Pull Request" button. 55 | - Select your branch (`YourRollNumber`) in the base repository and create the pull request. 56 | 57 | ## Issue Assignment 58 | 59 | Contributors can choose any one of the 20 CP questions to solve. Issues will be assigned to contributors in chronological order. Wait for your issue to be assigned before starting to work on it. 60 | 61 | ## CP Question Types 62 | 63 | "There are four types of CP questions: 64 | 65 | 1. **Provide a Solution for the Question** 66 | 2. **Fix Bugs in the Code** 67 | 3. **Optimize the Solution** 68 | 4. **Provide a Different Approach** 69 | 70 | Points will be assigned based on the type of questions you have solved." 71 | 72 | ## Issue Deadlines 73 | 74 | Issues will be initially assigned for 12 hours. If a contributor does not submit a pull request within this timeframe, the issue will be reassigned. 75 | 76 | ## Doubts and Clarifications 77 | 78 | If you have any doubts or need clarifications, please ask in the Discord of GDSC IIITL: [GDSC IIITL Discord Server](https://discord.gg/NUdeuTy33Z). 79 | 80 | ## Additional Notes 81 | 82 | - Commit all your changes related to different questions in the same branch named with your roll number. 83 | - Commit your changes frequently and use descriptive commit messages. 84 | - Test your changes thoroughly before submitting a pull request. 85 | - Unassigned pull requests will not be considered. 86 | 87 | ## GitHub Repository 88 | 89 | You can find additional issues in the GitGrind:CP Edition here: [issues](https://github.com/DSC-IIITL/GitGrind/issues) 90 | 91 | ## Conclusion 92 | 93 | We hope this guide has provided you with the information needed to contribute effectively to GitGrind:CP Edition. Your contributions are invaluable, and we look forward to your pull requests! Happy coding! 🚀 94 | -------------------------------------------------------------------------------- /Students/LCB2023030/Solution/Question_3.md.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | int main() 11 | { 12 | int t{}; 13 | cin >> t; 14 | for (int i{}; i < t; ++i) 15 | { 16 | int n, k; 17 | cin >> n >> k; 18 | int chocolate = n; 19 | int c = n / k; 20 | if ((n%k) == 0) 21 | { 22 | cout << n << '\n'; 23 | continue; 24 | } 25 | while (n > k) 26 | { 27 | n = n - k; 28 | } 29 | int e = k / 2; 30 | 31 | cout << chocolate - (chocolate % k) + e << '\n'; 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Students/LCB2023032/Fix_Bugs/Register_Username.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void registerUsernames(int n) 5 | { 6 | map database; 7 | 8 | for (int i = 0; i < n; i++) 9 | { 10 | string s; 11 | cin >> s; 12 | 13 | if (database.count(s) == 0) 14 | { 15 | cout << "OK" << endl; 16 | database[s] = 1; 17 | } 18 | else 19 | { 20 | while (true) 21 | { 22 | string newUsername = s + to_string(database[s]); 23 | if (database.count(newUsername) == 0) 24 | { 25 | // database.count(newUsername); 26 | cout<< newUsername << endl; 27 | database[newUsername] = 1; 28 | break; 29 | } 30 | database[s]++; 31 | } 32 | } 33 | } 34 | } 35 | 36 | int main() 37 | { 38 | int n; 39 | cout << "Enter the number of username registration attempts: "; 40 | cin >> n; 41 | registerUsernames(n); 42 | return 0; 43 | } 44 | 45 | // There are few Logical errors in the code. Fix them and submit the code. -------------------------------------------------------------------------------- /Students/LCB2023032/Fix_Bugs/Sorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | 6 | 7 | void merge( ll l , ll r ,ll mid, vector& arr){ 8 | 9 | ll size_temp1 = mid - l + 1; 10 | ll size_temp2 = r - mid; 11 | vector temp1(size_temp1), temp2(size_temp2); 12 | 13 | 14 | 15 | for(ll i = 0; i< size_temp1;++i){ 16 | temp1[i] = arr[i+l]; 17 | } 18 | for(ll i = 0; i< size_temp2 ;++i){ 19 | temp2[i] = arr[i+mid+1]; 20 | } 21 | 22 | ll point_temp1 = 0, point_temp2 = 0, point_arr = l; 23 | 24 | while(point_temp1& arr){ 46 | if(l>1; 48 | // cout<<"mid: "<>n; 63 | // cout<<"stated \n"; 64 | vector arr(n); 65 | // cout<<"arr defined \n"; 66 | for(int i = 0; i>arr[i]; 68 | } 69 | // cout<<"before soring \n"; 70 | // for(int i = 0; i>arr[i]; 8 | } 9 | int sum = 0; 10 | for(int i=0;i<10;i++){ 11 | sum += arr[i]; 12 | } 13 | cout << "Sum of 10 numbers is = " << sum << "\n"; 14 | } -------------------------------------------------------------------------------- /Students/LCI2023010/Alternate_Approach/gcd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int m,n,max,l,g; 7 | cout<<"Enter any two numbers:\n"; 8 | cin>>m>>n; 9 | max=(m>n) ? m:n; 10 | do 11 | { 12 | if(max%m==0 && max%n==0) 13 | { 14 | l=max; 15 | break; 16 | } 17 | else 18 | ++max; 19 | } while (1); 20 | g=(m*n)/l; 21 | cout<<"GCD is "< 2 | using namespace std; 3 | 4 | void Sort(int a[], int n) 5 | { 6 | int i, k, j; 7 | for (i = 1; i < n; i++) { 8 | k = a[i]; 9 | j = i - 1; 10 | 11 | while (j >= 0 && a[j] > k) { 12 | a[j + 1] = a[j]; 13 | j = j - 1; 14 | } 15 | a[j + 1] = k; 16 | } 17 | } 18 | int main() 19 | { 20 | int n; 21 | cin>>n; 22 | int a[n]; 23 | for(int i = 0; i>a[i]; 25 | } 26 | Sort(a, n); 27 | 28 | for(int i = 0; i 2 | using namespace std; 3 | 4 | int Josephus(int N, int k) 5 | { 6 | int i = 2, ans = 0; 7 | 8 | while (i <= N) { 9 | ans = (ans + k) % i; 10 | i++; 11 | } 12 | 13 | return ans + 1; 14 | } 15 | 16 | int main() 17 | { 18 | int N, k; 19 | cin >> N >> k; 20 | cout << Josephus(N, k) << endl; 21 | return 0; 22 | } 23 | // This is josephus problem. Fixed Bugs :) -------------------------------------------------------------------------------- /Students/LCI2023025/Fix_Bugs/Next_Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | vector nextGreaterElements(vector& nums) { 6 | int n = nums.size(); 7 | nums.resize(2 * n); 8 | vector res(n, -1); 9 | stack st; 10 | 11 | for (int i = 0; i < 2 * n; i++) { 12 | nums[i] = nums[i - n]; 13 | while (!st.empty() && nums[i % n] > nums[st.top()]) { 14 | int idx =st.top(); 15 | st.pop(); 16 | res[idx] = nums[i % n]; 17 | } 18 | st.push(i % n); 19 | } 20 | return res; 21 | } 22 | 23 | int main() { 24 | int n; 25 | cout << "Enter the number of elements in the circular array: "; 26 | cin >> n; 27 | 28 | vector nums(n); 29 | cout << "Enter the elements separated by spaces: "; 30 | for (int i = 0; i < n; i++) { 31 | cin >> nums[i]; 32 | } 33 | 34 | vector result = nextGreaterElements(nums); 35 | 36 | cout << "Next Greater Elements in Circular Array: "; 37 | for (int i = 0; i < n; i++) { 38 | cout << result[i] << " "; 39 | } 40 | cout << endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Students/LCI2023025/Solution/Question_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //the function we are going to use 5 | bool strictlyincreasingarray(int nums[], int length); 6 | 7 | 8 | //main function start here 9 | int main(){ 10 | //getting the length of array 11 | int length; 12 | 13 | cout<<"Enter the length of array : "<>length; 15 | 16 | int nums[length]; 17 | 18 | //getting the value for array 19 | cout<<"Start entering the value here :"<>nums[i]; 24 | } 25 | 26 | //calling hte function here 27 | bool work=strictlyincreasingarray(nums, length); 28 | 29 | //using the condition as per given question 30 | if(work==true) 31 | { 32 | cout<<"true"<=nums[i]) 57 | { 58 | if(check){ 59 | return false; //ending the function and giving false value as output 60 | }else{ 61 | check=true; //changing the bool value 62 | count++; 63 | for(int j=i; j>0;j--) 64 | { 65 | if (j > 1 && nums[j - 2] >= nums[j]) 66 | { 67 | nums[i] = nums[i - 1]; // Adjust the current element 68 | } 69 | } 70 | prev=nums[i]; //changing the value of prev 71 | } 72 | }else{ 73 | prev=nums[i]; //changing the value of prev 74 | } 75 | } 76 | return count<=1; //ending the function and giving true value as output 77 | } -------------------------------------------------------------------------------- /Students/LCI2023026/Solution/Question_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSC-IIITL/GitGrind/23ec2a4d9fe0a199f2dd0f47bf21f869e695f09c/Students/LCI2023026/Solution/Question_2 -------------------------------------------------------------------------------- /Students/LCI2023026/Solution/Question_2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve(){ 5 | // CODE HERE 6 | int a[4]; 7 | int count=0; 8 | for(int i=0; i<4; i++){ 9 | cin>>a[i]; 10 | if(a[i]==1){ 11 | count++; 12 | } 13 | } 14 | if(count==4){ 15 | cout<<2<<"\n"; 16 | } 17 | else if(count==0){ 18 | cout<<0<<"\n"; 19 | } 20 | else{ 21 | cout<<1<<"\n"; 22 | } 23 | } 24 | 25 | int main(){ 26 | int t; 27 | // Uncomment for multiple testcases 28 | cin >> t; 29 | while(t--){ 30 | solve(); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Students/LCI2023038/Alternate_Solution/Josephus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int Josephus(int N, int k) { 5 | if (N == 1) { 6 | return 1; 7 | } else { 8 | return (Josephus(N - 1, k) + k - 1) % N + 1; 9 | } 10 | } 11 | 12 | int main() { 13 | int N, k; 14 | cin >> N >> k; 15 | 16 | cout << Josephus(N, k) << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Students/LCI2023038/Alternate_Solution/power.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | double Power(double base, int exponent) { 5 | if (exponent == 0) { 6 | return 1.0; 7 | } 8 | if (exponent < 0) { 9 | base = 1.0 / base; 10 | exponent = -exponent; 11 | } 12 | if (exponent % 2 == 0) { 13 | double halfExponent = Power(base, exponent / 2); 14 | return halfExponent * halfExponent; 15 | } else { 16 | double halfExponent = Power(base, (exponent - 1) / 2); 17 | return base * halfExponent * halfExponent; 18 | } 19 | } 20 | 21 | 22 | int main() { 23 | double base; 24 | int exponent; 25 | cin >> base; 26 | cin >> exponent; 27 | double result = Power(base, exponent); 28 | cout << "Result: " << result << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Students/LCI2023038/FIx_Bugs/Missing_Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int findMissingNumber(vector& nums) { 5 | sort(nums.begin(), nums.end()); 6 | int n = nums.size(); 7 | unordered_set alreadyThere; 8 | for(int num : nums) 9 | alreadyThere.insert(num); 10 | 11 | for (int i = 1; i <= n; i++) { 12 | if (nums[i - 1] != i && alreadyThere.find(i)==alreadyThere.end()) { 13 | return i; 14 | } 15 | } 16 | return -1; 17 | } 18 | 19 | int main() { 20 | int n; 21 | cin >> n; 22 | vector nums(n); 23 | for (int i = 0; i < n; i++) { 24 | cin >> nums[i]; 25 | } 26 | int missing_number = findMissingNumber(nums); 27 | cout << missing_number << endl;//this ocde returns -1 if all the elements are present 28 | return 0; 29 | } 30 | 31 | // There are few Logical errors in the code. Fix them and submit the code. 32 | 33 | -------------------------------------------------------------------------------- /Students/LCI2023038/Solution/Question_6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int evenSum(vector& arr) { 5 | int eveSum = 0; 6 | for(int item : arr){ 7 | if(item%2 == 0){ 8 | eveSum+=item; 9 | } 10 | } 11 | return eveSum; 12 | } 13 | 14 | int main() { 15 | int n; 16 | cin >> n; 17 | vector arr(n); 18 | for (int i = 0; i < n; i++) { 19 | cin >> arr[i]; 20 | } 21 | int even_sum = evenSum(arr); 22 | cout << even_sum << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Students/LCS2022014/solution/example.cpp: -------------------------------------------------------------------------------- 1 | // #include 2 | // / ok done -------------------------------------------------------------------------------- /Students/LCS2023030: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin>>s; 8 | 9 | cout<<"Initial String: "< 4 | 5 | using namespace std; 6 | 7 | // Recursive function to find factorial of a number 8 | long long int factorial(long long int n){ 9 | if(n==0) return 1; 10 | 11 | return n*factorial(n-1); 12 | } 13 | 14 | 15 | int main(){ 16 | 17 | long long int n; 18 | cin>>n; // Input number 19 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int longest_Subarray_Length(int arr[], int n, int k) { 6 | map mpp; 7 | long long sum=0; 8 | int maxlen=0; 9 | for (int i=0;i> n; 32 | int arr[n]; 33 | cout << "Enter the elements of the array:\n"; 34 | for (int i = 0; i < n; ++i) { 35 | cin >> arr[i]; 36 | } 37 | 38 | cout << "Enter the value of k: "; 39 | cin >> k; 40 | 41 | int result = longest_Subarray_Length(arr, n, k); 42 | cout << "Length of the longest subarray with sum less than or equal to " << k << " is: " << result << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Students/LIT2023022/Fix_Bugs/Paired_Char.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int countPairedCharacters(int n, string s) 5 | { 6 | int freq[256]={0}; 7 | int cnt = 0; 8 | for (int i = 0; i < 2*n; i=i+2) 9 | { 10 | freq[s[i]]++; // updating frequency of charcters 11 | } 12 | 13 | for (int i=0;i<26; i++) { 14 | cnt=cnt+min(freq[65+i],freq[97+i]); //to include count of pair exactly once 15 | } 16 | return cnt; 17 | } 18 | 19 | 20 | int main() 21 | { 22 | int n; 23 | cin >> n; 24 | string s; 25 | cin >> s; 26 | 27 | int result = countPairedCharacters(n, s); 28 | 29 | cout << result << endl; 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Students/LIT2023022/solution/Question_7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int compare(map,map); 5 | int compare(mapmpp,mapmpp2){ 6 | int c=0; 7 | for (auto it:mpp){ 8 | if (it.second!=mpp2[it.first]){ 9 | c=0; 10 | return 0; 11 | } 12 | else{ 13 | c=1; 14 | } 15 | 16 | } 17 | if (c>0){ 18 | return 1; 19 | } 20 | return 0; 21 | } 22 | 23 | int func(vector vec,int n){ 24 | map mpp3; 25 | for (int i=0;i mpp; 27 | for(int k=0;k mpp2; 33 | for(int k=0;k>n; 55 | vector v; 56 | for(int i=0;i>s; 59 | v.push_back(s); 60 | } 61 | 62 | func(v,n); 63 | } -------------------------------------------------------------------------------- /Students/LIT2023044/Optimize_solution/fibonacci.cpp: -------------------------------------------------------------------------------- 1 | // Print the fibonacci series upto the given number 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | int a=0,b=1,c=0; 10 | for(int i=1;i<=n;i++) 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | bool isPalindrome(string str,int right) { 5 | 6 | int i; 7 | for(i=0;i<=right/2;i++){ 8 | if(str[i] != str[right -i]) 9 | return false; 10 | 11 | } 12 | return true; 13 | } 14 | 15 | int main() { 16 | string str; 17 | cout << "Enter a string: "; 18 | cin >> str; 19 | 20 | if (isPalindrome(str, str.length() - 1)) { 21 | cout << " Palindrome." << endl; 22 | } else { 23 | cout << " Not a Palindrome." << endl; 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Students/lci2023032/palindrome.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DSC-IIITL/GitGrind/23ec2a4d9fe0a199f2dd0f47bf21f869e695f09c/Students/lci2023032/palindrome.exe -------------------------------------------------------------------------------- /Students/lcs2022049/helloworld.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | cout<<"Hello world"; 6 | return 0; 7 | } -------------------------------------------------------------------------------- /Students/lit2023011/Alternate_approach/TOH_alt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void TOH(int n,char A,char B,char C){ 5 | if(n>0){ 6 | TOH(n-1,A,C,B); 7 | cout<<"Move a Disc from "<> num_disks; 15 | TOH(num_disks,'A','B','C'); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Students/lit2023011/solution/Question_4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int length, max[3] = {-1, -1, -1}; 7 | cout << "Enter the length of array:" << endl; 8 | cin >> length; 9 | int *arr = new int[length]; 10 | cout << "Enter each number of the array" << endl; 11 | 12 | for (int i = 0; i < length; i++) 13 | { 14 | cin >> arr[i]; 15 | if (max[0] != arr[i] && max[1] != arr[i] && max[2] != arr[i]) 16 | { 17 | if (max[0] < arr[i]) 18 | { 19 | max[2] = max[1]; 20 | max[1] = max[0]; 21 | max[0] = arr[i]; 22 | } 23 | else if (max[1] < arr[i]) 24 | { 25 | max[2] = max[1]; 26 | max[1] = arr[i]; 27 | } 28 | else if (max[2] < arr[i]) 29 | { 30 | max[2] = arr[i]; 31 | } 32 | } 33 | } 34 | if (max[2] == -1) 35 | { 36 | cout << max[0]; 37 | } 38 | else 39 | { 40 | cout << max[2]; 41 | } 42 | 43 | delete[] arr; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Students/readme.md: -------------------------------------------------------------------------------- 1 | This is a demo readme -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | ### Issue Type: [Provide Solution/Fix Bugs/Optimize Solution/Different Approach] 2 | 3 | ### Description: 4 | 5 | [Provide a detailed description of the issue. Include the problem statement, relevant code snippets (if applicable), and any additional context necessary for understanding the problem.] 6 | 7 | ### Proposed Changes: 8 | 9 | [Describe the changes you plan to make to address the issue. If you're providing a solution, include the code snippets or algorithm you intend to implement. For bug fixes, explain the changes you will make to resolve the bug.] 10 | 11 | ### Additional Information (if any): 12 | 13 | [Include any additional information that might be helpful in understanding the issue, such as environment details, related issues, etc.] 14 | 15 | --- 16 | 17 | **Note:** 18 | 19 | - Please make sure to follow the guidelines mentioned in the README file. 20 | - Commit your changes frequently and use descriptive commit messages. 21 | - If you have any doubts or need clarifications, reach out on the [GDSC IIITL Discord Server](https://discord.gg/NUdeuTy33Z). 22 | 23 | Happy coding! 🚀 24 | --------------------------------------------------------------------------------