diff --git a/Diagonal traverese.cpp b/Diagonal traverese.cpp new file mode 100644 index 00000000..3a1a6ca5 --- /dev/null +++ b/Diagonal traverese.cpp @@ -0,0 +1,58 @@ +class Solution {//time compleaxity o(m*n)and space complexity o(1) +public: + vector findDiagonalOrder(vector>& mat) { + if(mat.size()==0) + return {}; + int m =mat.size(); + int n= mat[0].size(); + vectorresult(n*m); + bool dir =true; + int r =0,c=0; + + for(int i=0;i productExceptSelf(vector& nums) { + vectorresult; + result[0]=1; + for(int i =1;i=0;i++) + { + result[i]=result[i]*right; + right = right*nums[i]; + i--; + } + + return result; + } +}; \ No newline at end of file diff --git a/spiral matrix.cpp b/spiral matrix.cpp new file mode 100644 index 00000000..e09886d7 --- /dev/null +++ b/spiral matrix.cpp @@ -0,0 +1,31 @@ +class Solution {//tc:O(m*n),sc:O(1) +public: + vector spiralOrder(vector>& matrix) { + if(matrix.size()==0) + return {}; + int m =matrix.size(); + int n= matrix[0].size(); + int l =0,r=n-1,t=0,b=m-1;//left,right,top ,bottom + vectorresult; + while(l<=r && t<=b) + { + for(int i =l;i<=r;i++) + result.push_back(matrix[t][i]); + t++; + for(int i =t;i<=b;i++) + result.push_back(matrix[i][r]); + r--; + if(t<=b){ // to avoid duplicates + for(int i =r;i>=l;i--) + result.push_back(matrix[b][i]); + b--; + } + if(l<=r){ + for(int i =b;i>=t;i--) + result.push_back(matrix[i][l]); + l++; + } + } + return result; + } +}; \ No newline at end of file