✌️2 solutions ||✅ Easy Approach explained with example ||⌛Time & Space Complexity ||
Do upvote\uD83D\uDD3C if it adds value !\n\n# Approach : \n Describe your approach to solving the problem. \n- consider a  1D array(with all zeroes) of size say
### Do upvote\uD83D\uDD3C if it adds value !\n\n# Approach : \n<!-- Describe your approach to solving the problem. -->\n- consider a  1D array(with all zeroes) of size say 6(say n).\nwe have queries to set all indexes to 1 for [0,3],[2,4] and [4,5] (index1 , index2) , what we could do is : \n\n- increment index1 by 1 and decrement index2+1( if <=n-1) by 1  \n```\n-> for [0,3] we have array as [1,0,0,0,-1,0]\n-> Now [2,4] makes array as [1,0,1,0,-1,-1]\n-> Now [4,5] makes array as [1,0,1,0,0,-1]\n```\n\n\n- Now perform operation array[i]+=array[i-1] for all  i (n-1>=i>0)\n```\nWe get our final array as [1,1,2,2,2,1] which is desired array .\n```\n\n\nApplying the same concept in 2D array in the below 2 solutions : )\n\n\n \n\n# Complexity\n#### \u2714 Time complexity:O(n\xD7(queries_length))+O(n\xD7n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n#### \u2714 Space complexity:O(n\xD7n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code 1 :Applying the above 1D array concept row-wise \n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> ans(n,vector<int>(n,0));\n        vector<int> row(n,0);\n        vector<int> col(n,0);\n        for(int i=0 ; i<queries.size() ; i++){\n            for(int j=queries[i][0] ; j<=queries[i][2] ; j++){\n                ans[j][queries[i][1]]+=1;\n                if(queries[i][3]+1<n){\n                    ans[j][queries[i][3]+1]-=1;\n                }\n            }\n        }\n        for(int i=0 ; i<n ; i++)\n        {\n            for(int j=1 ; j<n ; j++){\n                ans[i][j]+=ans[i][j-1];\n            }\n        }   \n        return ans;\n    }\n};\n```\n\n# Code 2 : Applying the above 1D array concept column-wise\n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> ans(n,vector<int>(n,0));\n        vector<int> row(n,0);\n        vector<int> col(n,0);\n        for(int i=0 ; i<queries.size() ; i++){\n            for(int j=queries[i][1] ; j<=queries[i][3] ; j++){\n                ans[queries[i][0]][j]+=1;\n                if(queries[i][2]+1<n){\n                    ans[queries[i][2]+1][j]-=1;\n                }\n            }\n        }\n        for(int i=0 ; i<n ; i++)\n        {\n            for(int j=1 ; j<n ; j++){\n                ans[j][i]+=ans[j-1][i];\n            }\n        }   \n        return ans;\n    }\n};\n```
['C++']