From 48de14741b8447ee26666553e70a87f34d528312 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Mon, 7 Dec 2020 19:44:57 +0530 Subject: [PATCH 01/18] Create Shriya_Rai --- Week1/Missing no/Shriya_Rai | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Week1/Missing no/Shriya_Rai diff --git a/Week1/Missing no/Shriya_Rai b/Week1/Missing no/Shriya_Rai new file mode 100644 index 0000000..348a1ea --- /dev/null +++ b/Week1/Missing no/Shriya_Rai @@ -0,0 +1,12 @@ +class Solution { +public: + int missingNumber(vector& nums) { + int n=nums.size(); + int tsum=n*(n+1)/2; + int sum=0; + for(int i=0;i Date: Mon, 7 Dec 2020 19:45:51 +0530 Subject: [PATCH 02/18] Create Shriya_Rai --- Week1/Remove Duplicates/Shriya_Rai | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Week1/Remove Duplicates/Shriya_Rai diff --git a/Week1/Remove Duplicates/Shriya_Rai b/Week1/Remove Duplicates/Shriya_Rai new file mode 100644 index 0000000..1aa0fd0 --- /dev/null +++ b/Week1/Remove Duplicates/Shriya_Rai @@ -0,0 +1,15 @@ +class Solution { +public: + int removeDuplicates(vector& nums) { + int n=nums.size(); + if (n==0) return 0; + int j=1; + for(int i=0;i Date: Mon, 7 Dec 2020 19:47:57 +0530 Subject: [PATCH 03/18] Create Shriya_Rai --- Week1/Rotate Array/Shriya_Rai | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week1/Rotate Array/Shriya_Rai diff --git a/Week1/Rotate Array/Shriya_Rai b/Week1/Rotate Array/Shriya_Rai new file mode 100644 index 0000000..b438f53 --- /dev/null +++ b/Week1/Rotate Array/Shriya_Rai @@ -0,0 +1,22 @@ +class Solution { +public: + void reversearray(vector& nums,int low,int high){ + while(low& nums, int k) { + int n=nums.size(); + k%=n; + reversearray(nums,0,n-1); + reversearray(nums,0,k-1); + reversearray(nums,k,n-1); + + } +}; From a8b05c4de99df278f1a1971b6b52b91b9757c910 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:15:06 +0530 Subject: [PATCH 04/18] Create Shriya_Rai --- Week1/Max Subarray/Shriya_Rai | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week1/Max Subarray/Shriya_Rai diff --git a/Week1/Max Subarray/Shriya_Rai b/Week1/Max Subarray/Shriya_Rai new file mode 100644 index 0000000..fccf79f --- /dev/null +++ b/Week1/Max Subarray/Shriya_Rai @@ -0,0 +1,14 @@ +int sum=0; + int maxsum=INT_MIN; + for(int i=0;imaxsum) + { + maxsum=sum; + } + if (sum<0) + sum=0; + } + return maxsum; + } From b16fa23c5af7fbc5af71e3e59b4deec59e9aed90 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:31:48 +0530 Subject: [PATCH 05/18] Create Shriya_Rai --- Week1/Spiral Matrix/Shriya_Rai | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Week1/Spiral Matrix/Shriya_Rai diff --git a/Week1/Spiral Matrix/Shriya_Rai b/Week1/Spiral Matrix/Shriya_Rai new file mode 100644 index 0000000..e034cec --- /dev/null +++ b/Week1/Spiral Matrix/Shriya_Rai @@ -0,0 +1,34 @@ +class Solution { +public: + vector spiralOrder(vector>& matrix) { + vector curPos {0,0}; + vector result; + vector> dirs {{0,1},{1,0},{0,-1},{-1,0}}; + int curDir = 0; + + int RSize = matrix.size(); + int CSize = matrix[0].size(); + int numsSize = CSize * RSize; + + for(int i=0; i< numsSize; i++) { + //cout<= CSize || nextC < 0 || nextR >= RSize || nextR < 0 || matrix[nextR][nextC] == 101) { + nextR -= dirs[curDir][0]; + nextC -= dirs[curDir][1]; + curDir++; + if(curDir > 3) curDir = 0; + nextR += dirs[curDir][0]; + nextC += dirs[curDir][1]; + } + curPos[0] = nextR; + curPos[1] = nextC; + } + return result; + } +}; From 79d9d72e77d8d7c100ca5ec24ecdd5c3c5dd4c66 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:35:36 +0530 Subject: [PATCH 06/18] Create Shriya_Rai --- Week1/Product Of Array/Shriya_Rai | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Week1/Product Of Array/Shriya_Rai diff --git a/Week1/Product Of Array/Shriya_Rai b/Week1/Product Of Array/Shriya_Rai new file mode 100644 index 0000000..7f89118 --- /dev/null +++ b/Week1/Product Of Array/Shriya_Rai @@ -0,0 +1,36 @@ +class Solution { +public: + vector productExceptSelf(vector& nums) { + int length = nums.size(); + + vector L(length); + vector R(length); + + + vector answer(length); + + + + L[0] = 1; + for (int i = 1; i < length; i++) { + + L[i] = nums[i - 1] * L[i - 1]; + } + + + R[length - 1] = 1; + for (int i = length - 2; i >= 0; i--) { + + + R[i] = nums[i + 1] * R[i + 1]; + } + + + for (int i = 0; i < length; i++) { + + answer[i] = L[i] * R[i]; + } + + return answer; + } +}; From 96a0f44a12338faf87f6e29debd6ecf217565822 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:41:09 +0530 Subject: [PATCH 07/18] Create Shriya_Rai --- Week1/Move Zeroes/Shriya_Rai | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Week1/Move Zeroes/Shriya_Rai diff --git a/Week1/Move Zeroes/Shriya_Rai b/Week1/Move Zeroes/Shriya_Rai new file mode 100644 index 0000000..919459e --- /dev/null +++ b/Week1/Move Zeroes/Shriya_Rai @@ -0,0 +1,12 @@ +class Solution { +public: + void moveZeroes(vector& nums) { + if(nums.size() == 0) return; + int p = -1; + int i = 0; + while(i < nums.size()){ + if(nums[i] != 0) swap(nums[++p], nums[i]); + i++; + } + } +}; From 1954bc84ce85eb6d3a06716bda919a167a561822 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:43:04 +0530 Subject: [PATCH 08/18] Create Shriya_Rai --- Week1/Pivot Index/Shriya_Rai | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week1/Pivot Index/Shriya_Rai diff --git a/Week1/Pivot Index/Shriya_Rai b/Week1/Pivot Index/Shriya_Rai new file mode 100644 index 0000000..f77a4ca --- /dev/null +++ b/Week1/Pivot Index/Shriya_Rai @@ -0,0 +1,26 @@ +class Solution { +public: + int pivotIndex(vector& nums) { + int leftSum=0, rightSum=0, sum=0; + for(int i=0; i Date: Tue, 8 Dec 2020 12:46:29 +0530 Subject: [PATCH 09/18] Create Shriya_Rai --- Week1/Monotonic Array/Shriya_Rai | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week1/Monotonic Array/Shriya_Rai diff --git a/Week1/Monotonic Array/Shriya_Rai b/Week1/Monotonic Array/Shriya_Rai new file mode 100644 index 0000000..252dd54 --- /dev/null +++ b/Week1/Monotonic Array/Shriya_Rai @@ -0,0 +1,22 @@ +class Solution { +public: + bool isMonotonic(vector& A) { + bool isIncreasing = A[0] < A[A.size()-1]; //Checking array is increasing + + for(int i = 0; i < A.size() - 1 ; i++) + { + if(isIncreasing) + { + if(A[i] > A[i+1]) + return false; + } + else + { + if(A[i] < A[i+1]) + return false; + } + } + + return true; + } +}; From a2458808d99588fdf5439f03c198ad8a0fbad714 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:49:11 +0530 Subject: [PATCH 10/18] Create Shriya_Rai --- Week1/Xor operation/Shriya_Rai | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Week1/Xor operation/Shriya_Rai diff --git a/Week1/Xor operation/Shriya_Rai b/Week1/Xor operation/Shriya_Rai new file mode 100644 index 0000000..41d2411 --- /dev/null +++ b/Week1/Xor operation/Shriya_Rai @@ -0,0 +1,10 @@ +class Solution { +public: + int xorOperation(int n, int start) { + int res = start; + for(int i = 1; i Date: Tue, 8 Dec 2020 12:51:14 +0530 Subject: [PATCH 11/18] Create Shriya_Rai --- Week1/Pascal Triangle/Shriya_Rai | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Week1/Pascal Triangle/Shriya_Rai diff --git a/Week1/Pascal Triangle/Shriya_Rai b/Week1/Pascal Triangle/Shriya_Rai new file mode 100644 index 0000000..eba8389 --- /dev/null +++ b/Week1/Pascal Triangle/Shriya_Rai @@ -0,0 +1,15 @@ +class Solution { +public: + vector> generate(int numRows) { + vector>ans; + for(int i=0;irow(i+1,1); + for(int j=1;j Date: Tue, 8 Dec 2020 12:55:12 +0530 Subject: [PATCH 12/18] Create Shriya_Rai --- Week1/Count Negative Nos/Shriya_Rai | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Week1/Count Negative Nos/Shriya_Rai diff --git a/Week1/Count Negative Nos/Shriya_Rai b/Week1/Count Negative Nos/Shriya_Rai new file mode 100644 index 0000000..6085ee4 --- /dev/null +++ b/Week1/Count Negative Nos/Shriya_Rai @@ -0,0 +1,41 @@ +class Solution { +public: + int check(vector &vec) + { + int n=vec.size(); + int l=0,r=n-1,mid; + while(l<=r) + { + mid=l+(r-l)/2; + if(vec[mid]<0) + { + r=mid-1; + } + else + { + l=mid+1; + } + } + if(vec[mid]>=0 && mid==n-1) + { + return 0; + } + else if(vec[mid]>=0) + { + return n-mid-1; + } + else + { + return n-mid; + } + } + + int countNegatives(vector>& grid) { + int c=0; + for(auto &v: grid) + { + c=c+check(v); + } + return c; + } +}; From 05d387774a27ae4eb4b85ee8500f2c2e061260fa Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 12:58:02 +0530 Subject: [PATCH 13/18] Create Shriya_Rai --- Week1/Target Array/Shriya_Rai | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Week1/Target Array/Shriya_Rai diff --git a/Week1/Target Array/Shriya_Rai b/Week1/Target Array/Shriya_Rai new file mode 100644 index 0000000..7fccc6e --- /dev/null +++ b/Week1/Target Array/Shriya_Rai @@ -0,0 +1,9 @@ +class Solution { +public: + vector createTargetArray(vector& nums, vector& index) { + vector ans; + for(int i=0;i<(int)nums.size();i++) + ans.insert(ans.begin()+index[i],nums[i]); + return ans; + } +}; From 74548ffae53300de780c1710db3d785964afa545 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 13:02:25 +0530 Subject: [PATCH 14/18] Create Shriya_Rai --- Week1/Count and Say/Shriya_Rai | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week1/Count and Say/Shriya_Rai diff --git a/Week1/Count and Say/Shriya_Rai b/Week1/Count and Say/Shriya_Rai new file mode 100644 index 0000000..be28520 --- /dev/null +++ b/Week1/Count and Say/Shriya_Rai @@ -0,0 +1,20 @@ +class Solution { +public: + string countAndSay(int n) { + if (n == 0) return ""; + string res = "1"; + while (--n) { + string cur = ""; + for (int i = 0; i < res.size(); i++) { + int count = 1; + while ((i + 1 < res.size()) && (res[i] == res[i + 1])){ + count++; + i++; + } + cur += to_string(count) + res[i]; + } + res = cur; + } + return res; + } +}; From 9207b9ec0b2c6df6842c5bd1ddacfba86984d14a Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 13:04:27 +0530 Subject: [PATCH 15/18] Create Shriya_Rai --- Week1/Valid Palindrome/Shriya_Rai | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Week1/Valid Palindrome/Shriya_Rai diff --git a/Week1/Valid Palindrome/Shriya_Rai b/Week1/Valid Palindrome/Shriya_Rai new file mode 100644 index 0000000..2ef18b2 --- /dev/null +++ b/Week1/Valid Palindrome/Shriya_Rai @@ -0,0 +1,12 @@ +class Solution { +public: + bool isPalindrome(string s) { + for (int i = 0, j = s.size() - 1; i < j; i++, j--) { + while (isalnum(s[i]) == false && i < j) i++; + while (isalnum(s[j]) == false && i < j) j--; + if (toupper(s[i]) != toupper(s[j])) return false; + } + + return true; + } +}; From 8a1f113ee20d1fa62cbaef8753df37462bc9e356 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 13:06:04 +0530 Subject: [PATCH 16/18] Create Shriya_Rai --- Week1/Reverse Only Letters/Shriya_Rai | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Week1/Reverse Only Letters/Shriya_Rai diff --git a/Week1/Reverse Only Letters/Shriya_Rai b/Week1/Reverse Only Letters/Shriya_Rai new file mode 100644 index 0000000..f985ca3 --- /dev/null +++ b/Week1/Reverse Only Letters/Shriya_Rai @@ -0,0 +1,13 @@ +class Solution { +public: + string reverseOnlyLetters(string S) { + int first=-1, last=S.size(); + while(true) { + while(first Date: Tue, 8 Dec 2020 13:08:11 +0530 Subject: [PATCH 17/18] Create Shriya_Rai --- .../Shriya_Rai | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week1/Longest Substring wo repeating chars/Shriya_Rai diff --git a/Week1/Longest Substring wo repeating chars/Shriya_Rai b/Week1/Longest Substring wo repeating chars/Shriya_Rai new file mode 100644 index 0000000..c874d1e --- /dev/null +++ b/Week1/Longest Substring wo repeating chars/Shriya_Rai @@ -0,0 +1,14 @@ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + vector dict(256, -1); + int maxLen = 0, start = -1; + for (int i = 0; i != s.length(); i++) { + if (dict[s[i]] > start) + start = dict[s[i]]; + dict[s[i]] = i; + maxLen = max(maxLen, i - start); + } + return maxLen; + } +}; From 47ba573927595ad7694e6bfcc21c44b7da202df5 Mon Sep 17 00:00:00 2001 From: Shriya-Rai <48272365+Shriya-Rai@users.noreply.github.com> Date: Tue, 8 Dec 2020 13:10:03 +0530 Subject: [PATCH 18/18] Create Shriya_Rai --- Week1/Reverse vowels/Shriya_Rai | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week1/Reverse vowels/Shriya_Rai diff --git a/Week1/Reverse vowels/Shriya_Rai b/Week1/Reverse vowels/Shriya_Rai new file mode 100644 index 0000000..204a36b --- /dev/null +++ b/Week1/Reverse vowels/Shriya_Rai @@ -0,0 +1,22 @@ +class Solution { +public: + string reverseVowels(string s) { + int i=0; + int j=s.size()-1; + while(i