From 7f4df20eaaf504b8dbcd67507d964d5ce52e1551 Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Fri, 12 Nov 2021 17:04:09 +0530 Subject: [PATCH 01/10] substring problem --- DAY52/substring.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 DAY52/substring.cpp diff --git a/DAY52/substring.cpp b/DAY52/substring.cpp new file mode 100644 index 0000000..1f2a321 --- /dev/null +++ b/DAY52/substring.cpp @@ -0,0 +1,17 @@ +#include +#include +using namespace std; +int32_t main(){ + string s = "abcabcabc"; + int n = s.size(); + //cin >> s; + vector dict(256,-1); + int maxl =0;int start =-1; + for(int i=0;i start) + start = dict[s[i]]; + dict[s[i]] = i; + maxl = max(maxl , i-start); + } + cout << maxl; +} \ No newline at end of file From bd7fafb4cb429d10cee5c2543508d9bb2e103fbc Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Sat, 13 Nov 2021 19:52:03 +0530 Subject: [PATCH 02/10] Print Matrix in Snake Pattern --- DAY53/print_matrix_in_snake_pattern.cpp | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 DAY53/print_matrix_in_snake_pattern.cpp diff --git a/DAY53/print_matrix_in_snake_pattern.cpp b/DAY53/print_matrix_in_snake_pattern.cpp new file mode 100644 index 0000000..2d8cf20 --- /dev/null +++ b/DAY53/print_matrix_in_snake_pattern.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +class Solution +{ + public: + //Function to return list of integers visited in snake pattern in matrix. + vector snakePattern(vector > arr) + { + // code here + int n = arr.size(); + vector v; + for(int i=0;i=0;j--){ + v.push_back(arr[i][j]); + + } + + } + } + return v; + } +}; \ No newline at end of file From a2de6de794994945b6a8e731f79bfab66a0fe8ee Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Tue, 16 Nov 2021 19:28:22 +0530 Subject: [PATCH 03/10] Kadane Algorithm --- DAY54/kadane_algorithm.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 DAY54/kadane_algorithm.cpp diff --git a/DAY54/kadane_algorithm.cpp b/DAY54/kadane_algorithm.cpp new file mode 100644 index 0000000..c25f7ed --- /dev/null +++ b/DAY54/kadane_algorithm.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; +int maxsum(vector arr){ + int curr_sum = 0; + int max_sum = INT_MIN; + for(const int x: arr){ + curr_sum += x; + max_sum = max(max_sum, curr_sum); + + } + return max_sum; +} +int main(){ + vector arr = {2, 5, 6, 7, 0, -8}; + int n = arr.size(); + cout << maxsum(arr) << endl; +} From 0015b48a3943ab7c71accf22c6c4ab8b3dbf011d Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Wed, 17 Nov 2021 13:52:36 +0530 Subject: [PATCH 04/10] Spiral Matrix --- DAY55/spiral.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 DAY55/spiral.cpp diff --git a/DAY55/spiral.cpp b/DAY55/spiral.cpp new file mode 100644 index 0000000..1d3910b --- /dev/null +++ b/DAY55/spiral.cpp @@ -0,0 +1,50 @@ +#include +#include +using namespace std; +vector spiralOrder(vector>& A) { +int T,B,L,R,dir; + T=0; + B=A.size()-1; + L=0; + R=A[0].size()-1; + dir=0; + int i; + vector ans; + + while(T<=B && L<=R) + { + if(dir==0) + { + for(i=L;i<=R;i++) + ans.push_back(A[T][i]); + T++; + } + else if(dir==1) + { + for(i=T;i<=B;i++) + ans.push_back(A[i][R]); + R--; + } + else if(dir==2) + { + for(i=R;i>=L;i--) + ans.push_back(A[B][i]); + B--; + } + else if(dir==3) + { + for(i=B;i>=T;i--) + ans.push_back(A[i][L]); + L++; + } + dir=(dir+1)%4; + } + return ans; +}; +int main(){ + vector> A = {{{1,2,3},{4,5,6},{7,8,9}}}; + for(int x: spiralOrder(A)){ + cout << x << " "; + } + +} \ No newline at end of file From 6f5423bb184fc94990d42818cf2b0d6a603ad360 Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Wed, 17 Nov 2021 13:54:18 +0530 Subject: [PATCH 05/10] KMP algorithm --- DAY56/kmp.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 DAY56/kmp.cpp diff --git a/DAY56/kmp.cpp b/DAY56/kmp.cpp new file mode 100644 index 0000000..f14bfe6 --- /dev/null +++ b/DAY56/kmp.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +int func (string s, string p , int n , int m){ + int count =0; + for(int i=0;i Date: Wed, 17 Nov 2021 13:56:18 +0530 Subject: [PATCH 06/10] XOR problem --- DAY57/xor_equation.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 DAY57/xor_equation.cpp diff --git a/DAY57/xor_equation.cpp b/DAY57/xor_equation.cpp new file mode 100644 index 0000000..d28d103 --- /dev/null +++ b/DAY57/xor_equation.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() { + int t; + cin >> t; + while(t--){ + int n; + int x; + cin >> n; + int count =0; + int arr[n]; + for(int i=0;i> arr[i]; + if((arr[i] +x) ^ (arr[i+1] +x) == 0){ + count++; + } + else + cout << -1 << endl; + } + cout << count << endl; + } + // your code goes here + return 0; +} From ade7fb47dc59ed97829ec95638c2fcdddb52ce10 Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Sun, 21 Nov 2021 12:44:21 +0530 Subject: [PATCH 07/10] Triplet with bitwise AND zero --- DAY58/triplet_with_bitwise_and.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 DAY58/triplet_with_bitwise_and.cpp diff --git a/DAY58/triplet_with_bitwise_and.cpp b/DAY58/triplet_with_bitwise_and.cpp new file mode 100644 index 0000000..bb86e09 --- /dev/null +++ b/DAY58/triplet_with_bitwise_and.cpp @@ -0,0 +1 @@ +solve(c , r,i, j); \ No newline at end of file From 3af14be6ed3ee552ac075a8cb0c4d7a2b2d4ba40 Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Sun, 21 Nov 2021 12:46:20 +0530 Subject: [PATCH 08/10] Search in array --- DAY59/search_int_rotated.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 DAY59/search_int_rotated.cpp diff --git a/DAY59/search_int_rotated.cpp b/DAY59/search_int_rotated.cpp new file mode 100644 index 0000000..849cc62 --- /dev/null +++ b/DAY59/search_int_rotated.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + int search(vector& nums, int target) { + int n = nums.size(); + int ans =0; + for(int i=0;i Date: Sun, 21 Nov 2021 12:48:22 +0530 Subject: [PATCH 09/10] Find all the disappeared numbers in array --- DAY60/find_all_numberdisappear_inarr.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 DAY60/find_all_numberdisappear_inarr.cpp diff --git a/DAY60/find_all_numberdisappear_inarr.cpp b/DAY60/find_all_numberdisappear_inarr.cpp new file mode 100644 index 0000000..3e9e0fc --- /dev/null +++ b/DAY60/find_all_numberdisappear_inarr.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + vector findDisappearedNumbers(vector& vec) { + vector mis; + + // For every given element + for (int i = 0; i < vec.size(); i++) { + + // Find its index + int temp = abs(vec[i]) - 1; + + // Update the element at the found index + vec[temp] = vec[temp] > 0 ? -vec[temp] : vec[temp]; + } + for (int i = 0; i < vec.size(); i++) + + // Current element was not present + // in the original vector + if (vec[i] > 0) + mis.push_back(i + 1); + + return mis; + } +}; \ No newline at end of file From 1638f73bfcdcfb1d91fc5d4e785c697c5490d792 Mon Sep 17 00:00:00 2001 From: yashasvi sakure Date: Wed, 24 Nov 2021 15:59:21 +0530 Subject: [PATCH 10/10] matrix --- DAY61/matrix.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 DAY61/matrix.cpp diff --git a/DAY61/matrix.cpp b/DAY61/matrix.cpp new file mode 100644 index 0000000..c8be288 --- /dev/null +++ b/DAY61/matrix.cpp @@ -0,0 +1,15 @@ +#include +#include +using namespace std; +int main(){ +vector> matrix; + int n = matrix.size(); + int m = matrix[0].size(); + for(int i=0;i> matrix[i][j]; + cout << matrix[i][j]; + } + } + return 0; +}