From 79142a6a396a3f09f53964b0e17e4c11deec60eb Mon Sep 17 00:00:00 2001 From: SejalAloria Date: Sun, 6 Dec 2020 19:28:07 +0530 Subject: [PATCH] Week 1 Sejal --- Week1/Count Negative Nos/Sejal Aloria | 14 +++++++++ Week1/Count and Say/Sejal Aloria | 21 ++++++++++++++ Week1/Max Subarray/Sejal Aloria | 12 ++++++++ Week1/Missing no/Sejal Aloria | 12 ++++++++ Week1/Monotonic Array/Sejal Aloria | 11 +++++++ Week1/Move Zeroes/Sejal Aloria | 22 ++++++++++++++ Week1/Pascal Triangle/Sejal Aloria | 15 ++++++++++ Week1/Pivot Index/Sejal Aloria | 17 +++++++++++ Week1/Product Of Array/Sejal Aloria | 18 ++++++++++++ Week1/Remove Duplicates/Sejal Aloria | 7 +++++ Week1/Rotate Array/Sejal Aloria | 11 +++++++ Week1/Spiral Matrix/Sejal Aloria | 41 +++++++++++++++++++++++++++ Week1/Target Array/Sejal Aloria | 10 +++++++ Week1/Valid Palindrome/Sejal Aloria | 19 +++++++++++++ Week1/Xor operation/Sejal Aloria | 12 ++++++++ 15 files changed, 242 insertions(+) create mode 100644 Week1/Count Negative Nos/Sejal Aloria create mode 100644 Week1/Count and Say/Sejal Aloria create mode 100644 Week1/Max Subarray/Sejal Aloria create mode 100644 Week1/Missing no/Sejal Aloria create mode 100644 Week1/Monotonic Array/Sejal Aloria create mode 100644 Week1/Move Zeroes/Sejal Aloria create mode 100644 Week1/Pascal Triangle/Sejal Aloria create mode 100644 Week1/Pivot Index/Sejal Aloria create mode 100644 Week1/Product Of Array/Sejal Aloria create mode 100644 Week1/Remove Duplicates/Sejal Aloria create mode 100644 Week1/Rotate Array/Sejal Aloria create mode 100644 Week1/Spiral Matrix/Sejal Aloria create mode 100644 Week1/Target Array/Sejal Aloria create mode 100644 Week1/Valid Palindrome/Sejal Aloria create mode 100644 Week1/Xor operation/Sejal Aloria diff --git a/Week1/Count Negative Nos/Sejal Aloria b/Week1/Count Negative Nos/Sejal Aloria new file mode 100644 index 0000000..0d059c9 --- /dev/null +++ b/Week1/Count Negative Nos/Sejal Aloria @@ -0,0 +1,14 @@ +class Solution { +public: + int countNegatives(vector>& grid) { + int count = 0; + + for(int i=0;i& nums) { + int cs=nums[0]; + int ms=nums[0]; + for(int i=1;i& nums) { + int n = nums.size(); + int sum=0; + int calsum = n*(n+1)/2; + for(int i=0;i& A) + { + auto inc = (A.front() <= A.back()); + for (int i=1; i A[i-1] && !inc)) + return false; + return true; + } +}; \ No newline at end of file diff --git a/Week1/Move Zeroes/Sejal Aloria b/Week1/Move Zeroes/Sejal Aloria new file mode 100644 index 0000000..c77c2e6 --- /dev/null +++ b/Week1/Move Zeroes/Sejal Aloria @@ -0,0 +1,22 @@ +class Solution { +public: + void moveZeroes(vector& nums) { + int numszero = 0; + for(int i=0;ians; + for(int i=0;i> generate(int numRows) { + vector>ans; + for(int i=0;irow(i+1,1); + for(int j=1;j& nums) { + int sum = 0; + for(int i:nums){ + sum+=i; + } + int left = 0; + for(int i=0;i productExceptSelf(vector& nums) { + int n = nums.size(); + int left = 1, right = 1; + vectorv; + for(int i=0;i=0;i--){ + v[i]=v[i]*right; + right=right*nums[i]; + } + return v; + + } +}; \ No newline at end of file diff --git a/Week1/Remove Duplicates/Sejal Aloria b/Week1/Remove Duplicates/Sejal Aloria new file mode 100644 index 0000000..6870533 --- /dev/null +++ b/Week1/Remove Duplicates/Sejal Aloria @@ -0,0 +1,7 @@ +class Solution { +public: + int removeDuplicates(vector& nums) { + return unique(nums.begin(), nums.end()) - nums.begin(); + + } +}; \ No newline at end of file diff --git a/Week1/Rotate Array/Sejal Aloria b/Week1/Rotate Array/Sejal Aloria new file mode 100644 index 0000000..3cf1b60 --- /dev/null +++ b/Week1/Rotate Array/Sejal Aloria @@ -0,0 +1,11 @@ +class Solution { +public: + void rotate(vector& nums, int k) { + int n=nums.size(); + k = k%n; + reverse(nums.begin(),nums.begin()+n-k); + reverse(nums.begin()+n-k,nums.end()); + reverse(nums.begin(),nums.end()); + + } +}; \ No newline at end of file diff --git a/Week1/Spiral Matrix/Sejal Aloria b/Week1/Spiral Matrix/Sejal Aloria new file mode 100644 index 0000000..f78dfbc --- /dev/null +++ b/Week1/Spiral Matrix/Sejal Aloria @@ -0,0 +1,41 @@ +class Solution { +public: + vector spiralOrder(vector>& matrix) { + + /*t->*/ int startrow = 0, /*b->*/ endrow = matrix.size(); + /*L->*/ int startcol = 0, /*r->*/ endcol = matrix[0].size(); + vectorres; + + while(startrow=startcol;i--) + res.push_back(matrix[endrow-1][i]); + endrow--; + if(startrow==endrow) + break; + + //startcol + for(int i=endrow-1;i>=startrow;i--) + res.push_back(matrix[i][startcol]); + startcol++; + + } + return res; + } +}; \ No newline at end of file diff --git a/Week1/Target Array/Sejal Aloria b/Week1/Target Array/Sejal Aloria new file mode 100644 index 0000000..afe4694 --- /dev/null +++ b/Week1/Target Array/Sejal Aloria @@ -0,0 +1,10 @@ +class Solution { +public: + vector createTargetArray(vector& nums, vector& index) { + vectorans; + for(int i=0;i