id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\n int minR(vector<int>& rc, vector<int>& cc, int r0, int c0, int r1, int c1) {\n int a=r0;\n while (a<=r1 and rc[a]==0) ++a;\n if (a>r1) return 0;\n int b=r1;\n while (b>a and rc[b]==0) --b;\n int c=c0;\n while (c<=c1 and cc[c]==0) ++c;\n... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int dp[31][31][31][31][3];\n int minimumArea(vector<vector<int>>& grid,int i1,int i2,int j1,int j2) {\n int ix=0,in=1e4,jx=0,jn=1e4;\n for(int i=i1;i<=i2;i++){\n for(int j=j1;j<=j2;j++){\n if(grid[i][j]){\n ix=max(... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "int dp[30][30][30][30];\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\n int n, m;\n const int INF = 1e6;\n\n struct Rectangle {\n int row_start, row_end, col_start, col_end;\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "int dp[30][30][30][30];\n\nclass Solution {\n int n, m;\n const int INF = 1e6;\n\n struct Rectangle {\n int row_start, row_end, col_start, col_end;\n inline int area() {\n if (row_start == INT_MAX) return 0;\n return (row_end - row_start + 1) * (col_end - col_st... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "int dp[30][30][30][30];\n\nclass Solution {\n int n, m;\n const int INF = 1e6;\n\n struct Rectangle {\n int row_start, row_end, col_start, col_end;\n inline int area() {\n if (row_start == INT_MAX) return 0;\n return (row_end - row_start + 1) * (col_end - col_st... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n auto sol = [](vector<vector<int>> &grid) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> topLeft(n, vector<int>(m));\n vector<vector<int>> bottomLeft(n, vector<int>(m));\n... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int cost(vector<int> coords, vector<vector<int>> &grid) {\n int stx = 35, sty = 35, enx = -1, eny = -1;\n for (int x = coords[0]; x <= coords[2]; x++) {\n for (int y = coords[1]; y <= coords[3]; y++) {\n if (grid[x][y] == 1) {\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int cost(vector<int> coords, vector<vector<int>> &grid) {\n int stx = 35, sty = 35, enx = -1, eny = -1;\n for (int x = coords[0]; x <= coords[2]; x++) {\n for (int y = coords[1]; y <= coords[3]; y++) {\n if (grid[x][y] == 1) {\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int cost(vector<int> coords, vector<vector<int>> &grid) {\n int stx = 35, sty = 35, enx = -1, eny = -1;\n for (int x = coords[0]; x <= coords[2]; x++) {\n for (int y = coords[1]; y <= coords[3]; y++) {\n if (grid[x][y] == 1) {\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int cost(vector<int> coords, vector<vector<int>> &grid) {\n int stx = 35, sty = 35, enx = -1, eny = -1;\n for (int x = coords[0]; x <= coords[2]; x++) {\n for (int y = coords[1]; y <= coords[3]; y++) {\n if (grid[x][y] == 1) {\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int dp[31][31][31][31][5];\n int find(vector<vector<int>>&grid, int sr,int sc,int er, int ec){\n int a=0;\n int b=INT_MAX;\n int c=INT_MAX;\n int d=0;\n int flag = 1;\n for(int i=sr;i<=er;i++){\n for(int j=sc;j<=ec;j++){... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int dp[31][31][31][31][5];\n int find(vector<vector<int>>&grid, int sr,int sc,int er, int ec){\n int a=0;\n int b=INT_MAX;\n int c=INT_MAX;\n int d=0;\n int flag = 1;\n for(int i=sr;i<=er;i++){\n for(int j=sc;j<=ec;j++){... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int get_one_rectangle_with_ones(vector<vector<int>> &grid,int r,int c,int m,int n){\n int sr=INT_MAX,sc=INT_MAX;\n int er=INT_MIN,ec=INT_MIN;\n\n for(int i=r;i<=m;i++){// why here i<=m\n for(int j=c;j<=n;j++){\n if(grid[i][j]==1)... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n unordered_map<string, int> memo;\n\n function<int(int, int, int, int, int)> getOne = [&](int i1, int j1, int i2, int j2, int k) {\n int minx... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n unordered_map<string, int> memo;\n\n function<int(int, int, int, int, int)> getOne = [&](int i1, int j1, int i2, int j2, int k) {\n int minx... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int dp[35][35][35][35][4];\n int n,m;\n int onesum(int x1,int y1,int x2,int y2,vector<vector<int>> &grid){\n int min1 = 1e9,min2 = 1e9,max1 = 0,max2 = 0;\n for(int i = x1; i <= x2; i++){\n for(int j = y1; j <= y2; j++){\n if(grid[... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, int> memo;\n vector<vector<int>> grid;\n\n int getOne(int i1, int j1, int i2, int j2) {\n int minx = INT_MAX;\n int maxx = INT_MIN;\n int miny = INT_MAX;\n int maxy = INT_MIN;\n\n for (int i = i1; i <= i2; ++i) {\... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n using rc = array<int,2>;\n using rect = array<rc, 2>; // min and max corners\n \n auto cover = [&grid](rect const& rec) {\n int lc = INT_MAX, uc = INT_MIN;\n int lr = INT_MAX, ur =... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n \n function<vector<int>(vector<vector<int>>&)> fn = [&](vector<vector<int>>& grid) {\n vector<int> ans; \n int imin = 30, jmin = 30, imax = 0, jmax = 0; \n for (int i = 0; i < grid.si... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n \n function<vector<int>(vector<vector<int>>&)> fn = [&](vector<vector<int>>& grid) {\n vector<int> ans; \n int imin = 50, jmin = 50, imax = -1, jmax = -1; \n for (int i = 0; i < grid.... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\npublic:\n int minimumSum(vector<vector<int>>& grid) {\n \n function<vector<int>(vector<vector<int>>&)> fn = [&](vector<vector<int>>& grid) {\n vector<int> ans; \n int imin = 30, jmin = 30, imax = 0, jmax = 0; \n for (int i = 0; i < grid.si... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\n int area(vector<pair<int, int> >& grid) {\n int upmin = INT_MAX, downmax = 0;\n int leftmin = INT_MAX, rightmax = 0;\n\n for(auto &[i, j]: grid){\n upmin = min(upmin, i);\n downmax = max(downmax, i);\n leftmin = min(leftmin, j);\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "class Solution {\n int minR(vector<vector<int>>& grid, int r0, int c0, int r1, int c1) {\n vector<int> rc(r1+1), cc(c1+1);\n for (int r=r0; r<=r1; ++r) {\n for (int c=c0; c<=c1; ++c) {\n rc[r]+=grid[r][c];\n cc[c]+=grid[r][c];\n }\n ... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\n public:\n int minimumSum(vector<vector<int>> &grid) {\n\n auto table = prepare_table(grid);... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\n public:\n int minimumSum(vector<vector<int>> &grid) {\n\n auto table = prepare_table(grid);\n std::function<int(size_t, size_t, size_t, size_t, int)> getOne =\n [&](size_t r1, size_t c1, size_t r2, size_t c2, in... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\n public:\n int minimumSum(vector<vector<int>> &grid) {\n\n auto table = prepare_table(grid);... |
3,459 | <p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
<p>Return the <strong>minimum</... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Table {\n Table(const Table &) = default;\n Table &operator=(const Table &) = default;\n Table(Table &&) = default;\n Table &operator=(Table &&) = default;\n std::vector<int> m;\n size_t col;\n size_t row;\n Table(size_t r, si... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 0 | {
"code": "class Solution {\npublic:\n int maxHeightOfTriangle(int red, int blue) {\n int max = 0;\n int current = 1;\n int currBlue = blue;\n int currRed = red;\n bool onBlue = true;\n while(currBlue >= 0 && currRed >= 0){\n if(onBlue){\n if(curr... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 0 | {
"code": "class Solution {\npublic:\n int maxHeightOfTriangle(int r, int b) {\n int red = r, blue = b;\n int ans = 0, balls = 1, height = 0;\n\n while (red + blue >= balls) {\n if (balls % 2 == 0)\n if (blue >= balls) blue -= balls;\n else break;\n ... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 0 | {
"code": "class Solution {\npublic:\n int maxHeightOfTriangle(int red, int blue) {\n return max(pattern(red, blue), pattern(blue, red));\n }\n int pattern(int red, int blue){\n int balls = 1, height = 0;\n while(true){\n red -= balls;\n if(red < 0)\n ... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 0 | {
"code": "class Solution {\npublic:\n int calculate_height(int a , int b){\n int height = 0;\n bool flag = true;\n int i = 1;\n while(flag){\n if(i%2 != 0 && a-i>=0){\n //odd level 1 3 5 7 ...\n height++;\n a = a - i;\n ... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 0 | {
"code": "class Solution {\npublic:\n\n int count(int red ,int blue,bool isred){\n int i =1 ;\n int cnt = 0;\n while(red>=0 && blue>=0){\n if(isred){\n if(red >=i){\n cnt++;\n red-=i;\n i++;\n ... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 1 | {
"code": "class Solution {\npublic:\n int maxHeightOfTriangle(int red, int blue) {\n return max(solve(red, blue), solve(blue, red));\n }\n int solve(int a, int b) {\n int lvl = 0, i = 1, j = 2;\n while(a >= 0 && b >= 0) {\n if(a - i >= 0) {\n a -= i;\n ... |
3,469 | <p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.<... | 1 | {
"code": "class Solution {\n int check(int first,int second)\n {\n int parity = 1;\n int total = 0;\n while(first >= 0 && second >= 0)\n {\n if(parity % 2 == 1)\n {\n first = first - parity;\n }\n else\n {\n ... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(const std::string& s) {\n int count = 0;\n int _max = 0;\n for (auto ch : s) {\n if (ch == 'E') {\n ++count;\n _max = std::max(_max, count);\n } else {\n --count;\n ... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int n=s.size(),cnt=0,mini=INT_MIN;\n int filled=0,empty=0;\n for(int i=0; i<n; i++){\n if(s[i]=='E' && empty==0){\n cnt++;\n filled++;\n } \n else if(s[i]=='E'... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int cnt = 0;\n int res = 0;\n for(auto c:s)\n {\n if(c=='E')\n {\n cnt++;\n res = max(cnt,res);\n }\n else cnt--;\n }\n return r... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int n=s.size();\n int count=0;\n int m=0;\n for(int i=0;i<n;i++){\n if(s[i]=='E'){\n count++;\n }\n if(s[i]=='L'){\n count--;\n }\n ... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int cnt=0, ans=0;\n for(auto it: s){\n if(it=='E') cnt++;\n else if(it=='L') cnt--;\n ans=max(cnt, ans);\n }\n return ans;\n }\n};",
"memory": "8600"
} |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 0 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int n=s.length();\n int l=0;int r=0;\n int mx=0;\n for(int i=0;i<n;i++){\n if(s[i]=='E') {l++;\n mx=max(mx,l);}\n else l--;\n }\n return mx;\n }\n};",
"memory": "86... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 1 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int n=s.size();\n int count=0;\n int m=0;\n for(int i=0;i<n;i++){\n if(s[i]=='E'){\n count++;\n }\n if(s[i]=='L'){\n count--;\n }\n ... |
3,426 | <p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>... | 1 | {
"code": "class Solution {\npublic:\n int minimumChairs(string s) {\n int n=s.size();\n int count=0;\n int m=0;\n for(int i=0;i<n;i++){\n if(s[i]=='E'){\n count++;\n }\n else if(s[i]=='L'){\n count--;\n }\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end(), [](auto& a, auto& b) {\n return a[0] != b[0]? a[0]... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end(), [](auto& a, auto& b) {\n return a[0] != b[0]? a[0]... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "static const auto boost = []() {\n std::cin.tie(0);\n std::cout.tie(0);\n std::ios::sync_with_stdio(false);\n return 0;\n}();\n\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n std::sort(meetings.begin(),meetings.end());\n int max_end = ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "static const auto boost = []() {\n std::cin.tie(0);\n std::cout.tie(0);\n std::ios::sync_with_stdio(false);\n return 0;\n}();\n\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n std::sort(meetings.begin(),meetings.end());\n int max_end = ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "static const auto boost = []() {\n std::cin.tie(0);\n std::cout.tie(0);\n std::ios::sync_with_stdio(false);\n return 0;\n}();\n\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n std::sort(meetings.begin(),meetings.end());\n int max_end = ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& m) {\n ios::sync_with_stdio(false);\n sort(m.begin(),m.end());\n\n int prev = m[0][1];\n int ans = m[0][0]-1;\n\n for(int i = 1; i < m.size(); i++){\n if((prev < m[i][0])){\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n int work = meetings[0][1]-meetings[0][0]+1;\n int max = meetings[0][1];\n for(int i = 1; i < meetings.size(); i++){\n if(meetings[i][1] ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n if(meetings.empty()) {\n return days;\n }\n\n // Sort meetings by their start day\n sort(meetings.begin(), meetings.end());\n \n int ans = 0;\n int current_start = meetings[0][0];\n int ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\npublic:\n int countDays(int days, std::vector<std::vector<int>>& meetings) {\n\n sort(meetings.begin() , meetings.end());\n\n int strt = meetings[0][0];\n int end = meetings[0][1];\n\n for(int i=1 ; i<meetings.size() ; i++){\n if(meetings[i][0] <=... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n \n // Just the extension of merge intervals problem\n\n if(meetings.size() == 1){\n int ans = 0; \n ans = ans + (meetings[0][1]-meetings[0][0]+1);\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 0 | {
"code": "class Solution {\n//TC:O(nlogn)\n//SC:O(nlogn)\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n int ans = 0, last = 0;\n\n // Sort meetings by their start day to process them in chronological order\n sort(meetings.begin(), meetings.end());\n\n // Process ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 1 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n int count = 0;\n int last=0;\n for (auto& meeting : meetings) {\n if (meeting[0]>last) {\n count += meeting[0] - last-1;\n }\n last... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 1 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n // for(auto it : meetings){\n // cout<<it[0]<<\" \"<<it[1]<<endl;\n // }\n\n int ans= 0;\n\n int left=meetings[0][0];\n in... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>merge(vector<vector<int>>&nums){\n vector<vector<int>>result;\n result.push_back(nums.front());\n for(int i=1;i<nums.size();i++)\n {\n if(result.back()[1]<nums[i][0]){\n result.push_back(nums[i]);\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> mergeIntervals(vector<vector<int>>& meetings){\n vector<vector<int>> ans;\n ans.push_back(meetings[0]);\n for(int i=1;i<meetings.size();i++){\n int last = ans.back()[1];\n if(last >= meetings[i][0]){\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n \n vector<vector<int>> mergeIntervals(vector<vector<int>>& a) {\n sort(a.begin(),a.end());\n \n vector<vector<int>> ans;\n \n int n=a.size();\n \n int s=a[0][0], e=a[0][1];\n for(int i=1;i<n;i++){\n int si=... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n \n vector<vector<int>> listM;\n\n auto curr=meetings[0];\n\n for(int i=1;i<meetings.size();i++){\n if(curr[1]>=meetings[i][0]... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& m) {\n if(m.size()==0 && days!=0)\n {\n return days;\n }\n if(m.size()==1)\n {\n int c = (m[0][1] - m[0][0]) + 1;\n return days-c;\n }\n vector<vecto... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\n /*\n normal merging inerval problem\n after doing merge interval, scan the merged days to find gaps \n between the separate intervals.\n add those gaps as those gaps are the days employee would be free.\n\n also make sure to consider edge cases\n 1. for example, the ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n \n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(),meetings.end());\n stack<pair<int,int>> mp;\n int ans=0;\n mp.push({meetings[0][0],meetings[0][1]});\n if(meetings[0][0])ans+=(meetings[0][0]-1);\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n stack<pair<int,int>>st;\n for (int i=0; i<meetings.size(); i++) {\n if (st.empty()) {\n st.push({meetings[i][0], meetings[i][1]}... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(),meetings.end());\n int ans = 0 ;\n stack<int> st ;\n st.push(0);\n int n = meetings.size();\n for(int i = 0 ;i<n;i++){\n if(meetings[i][0]>st... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n\n stack<pair<int,int>> s;\n\n sort(meetings.begin(),meetings.end());\n\n int n = meetings.size();\n\n for(int i=0;i<n;i++){\n\n int start_i = meetings[i][0];\n int e... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int day, vector<vector<int>>& meetings) {\n sort(meetings.begin(),meetings.end());\n vector<int>days;\n int cnt=0;\n // for(int i=0;i<meetings.size();i++){\n // cout<<meetings[i][0]<<\"-\"<<meetings[i][1]<<\" \";\n /... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n const int n = meetings.size();\n vector<int> inds(n);\n\n iota(inds.begin(), inds.end(... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end(), [](const vector<int>& lhs, const vector<int>& rhs) {\n if (lhs[0] != rhs[0])\n return lhs[0] < rhs[0];\n return lhs[1] < rhs[1];\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n int n = meetings.size();\n vector<pair<int,int>> v(n);\n for(int i = 0;i < n;i++){\n int a = meetings[i][0];\n int b = meetings[i][1];\n v[i] = {a,b};\n }\n... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& m) {\n sort(m.begin(), m.end());\n int n = m.size();\n\n vector<vector<int>> ans;\n\n ans.push_back(m[0]);\n\n for(int i=1; i<n;i++){\n if(ans.back()[1] >= m[i][0]){\n if... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n vector<vector<int>> copy;\n copy.push_back(meetings[0]);\n for (int i = 1; i < meetings.size(); i++) {\n int u = copy.back()[0];\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Interval\n{\npublic:\n int start, end;\n Interval(int start, int end) : start(start), end(end) {}\n void merge(Interval &other)\n {\n this->start = min(this->start, other.start);\n this->end = max(this->end, other.end);\n }\n\n bool can_merge(Interval &other)\n {\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n std::vector<Event> events;\n events.reserve(2*meetings.size());\n for(auto&& pair: meetings) {\n events.emplace_back(pair[0], Event::Start);\n events.emplace_back(pair[1], Ev... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "static auto fastio = []() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n};\n\nclass Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n fastio();\n int n = meetings.size();\n vector<pair<int, int>... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\nstatic bool cmp(const pair<int,int>&a,const pair<int,int>&b){\n return a.second<b.second;\n}\n int countDays(int days, vector<vector<int>>& m) {\n vector<pair<int,int>>vp;\n for(int i=0;i<m.size();i++){\n int a=m[i][0];\n int b=m[i][1];\n... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n typedef pair<int,int>PII;\n\n int countDays(int days, vector<vector<int>>& meetings) {\n vector<PII>vec;\n for(int i=0; i<meetings.size(); i++)\n vec.push_back({meetings[i][0], meetings[i][1]});\n sort(vec.begin(), vec.end());\n int k... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n int ct= 0;\n \n vector<pair<int,int>> arr;\n\n arr.push_back({0 , 0});\n int n = meetings.size();\n for(int i=0 ; i<n ; i++){\n arr.push_back({meetings[i][0] , meet... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n \n vector<pair<int, int>> m;\n for(int i = 0; i < meetings.size(); i++) {\n m.push_back({meetings[i][0], meetings[i][1]});\n }\n \n sort(m.begin(), m.end());\n\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n vector <int> meetingStart;\n vector <int> meetingEnd;\n\n for(int i =0 ; i < meetings.size() ;i++)\n {\n meetingStart.push_back(meetings[i][0]);\n meetingEnd.push_ba... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n\n vector <int> meetingStart;\n vector <int> meetingEnd;\n\n for(int i =0 ; i < meetings.size() ;i++)\n {\n meetingStart.push_back(meetings[i][0]);\n meetingEnd.push_ba... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int d, vector<vector<int>>& m) {\n /*vector<int> arr(d+2, 0);\n //arr[0]=0;\n for (int i=0; i!=m.size(); i++)\n {\n arr[m[i][0]]++;\n arr[m[i][1]+1]--;\n }\n int ans=0;\n //if (arr[0]>=1) ans... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n map<int, int> mp;\n mp[0] = 0;\n\n sort(meetings.begin(), meetings.end());\n\n int res = 0;\n for(const auto& meet : meetings) {\n int start = meet[0], end = meet[1];\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin() , meetings.end());\n int n = meetings.size();\n vector<vector<int>> ans;\n for(int i=0;i<meetings.size();i++)\n {\n if(!ans.empty() && ans.back()[1] ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin() , meetings.end());\n int n = meetings.size();\n vector<vector<int>> ans;\n for(int i=0;i<meetings.size();i++)\n {\n if(!ans.empty() && ans.back()[1] ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 2 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n map<int,int>m ;\n for(auto &it:meetings){\n int from = it[0] ;\n int to = it[1] ;\n if(m.find(from)==m.end())m[from]=to ;\n else{\n m[from]=max(... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n std::vector<std::pair<int, int>> events;\n \n // Add start and end events for each meeting\n f... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n std::vector<Event> events;\n\n for(auto&& pair: meetings) {\n events.emplace_back(pair[0], Event::Start);\n events.emplace_back(pair[1], Event::End);\n }\n std::sort(e... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n std::vector<Event> events;\n\n for(auto&& pair: meetings) {\n events.emplace_back(pair[0], Event::Start);\n events.emplace_back(pair[1], Event::End);\n }\n std::sort(e... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n vector<pair<int,int>>events;\n for (auto& meet : meetings) {\n events.push_back({meet[0], 0});\n events.push_back({meet[1], 1});\n }\n sort(events.begin(), events.end(... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n int count = 0;\n int last=0;\n for (auto x:meetings) {\n if (x[0]>last) {\n count += x[0] - last-1;\n }\n last=max(last,x[1]);\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n /*\n vector<bool> result(days, false);\n for (auto m : meetings) {\n for (int i = m[0] - 1; i <= m[1] - 1; i++) {\n result[i] = true;\n }\n }\n i... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n if (meetings.size()==1) return (days-1-(meetings[0][1]-meetings[0][0]));\n sort(meetings.begin(), meetings.end(), [](const vector<int>& a, const vector<int>& b) {\n return a[0] < b[0];\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>>ans ;\n if(intervals.size() == 0) return intervals ;\n\n sort(intervals.begin(), intervals.end()) ;\n vector<int>tempInterval = intervals[0] ;\n\n for(auto it... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n vector<vector<int>> mergedIntervals;\n if (meetings.size() == 0) {\n return days; \n }\n\n // Sort the meetings by start time\n sort(meetings.begin(), meetings.end());\n ... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> mergeIntervals(vector<vector<int>>& meetings) {\n sort(meetings.begin(), meetings.end());\n vector<vector<int>> merged;\n vector<int> act = meetings[0];\n\n for (vector<int> inter : meetings) {\n if (inter[0] <= act[1... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n \n\n vector<pair<int,int>>vi;\n int n = meetings.size();\n for(int i=0;i<n;i++)\n {\n vi.push_back({meetings[i][0],1});\n vi.push_back({meetings[i][1]+1,-1});\n... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n \n\n vector<pair<int,int>>vi;\n int n = meetings.size();\n for(int i=0;i<n;i++)\n {\n vi.push_back({meetings[i][0],1});\n vi.push_back({meetings[i][1]+1,-1});\n... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(vector<int> &a, vector<int> &b){\n if(a[0]==b[0]) return a[1]<=b[1];\n return a[0]<b[0];\n }\n int countDays(int n, vector<vector<int>>& nums) {\n sort(nums.begin(),nums.end(),comp);\n stack<vector<int>> st;\n st.push(... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\n int countDays(int days, vector<vector<int>>& meetings) {\n vector<pair<int,int>> vec;\n for(auto i:meetings){\n vec.push_back(make_pair(i[0], i[1]));\n } \n sort(vec.begin(), vec.end());\n int ans=0;\n if(vec[0].firs... |
3,430 | <p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of me... | 3 | {
"code": "class Solution {\npublic:\nint countDays(int days, vector<vector<int>>& meetings) {\n\tpriority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> pq;\n\tfor(auto m:meetings){\n\t\tpq.push({m[0],m[1]});\n\t}\n\tint ans=0,e=0;\n\twhile(pq.size()){\n\t\tauto [si,ei]=pq.top();\n\t\tpq.pop();\n\t\twhile(ei<e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.