id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
2
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int f(vector<vector<int>> &books, int shelfWidth, int n, int idx, int left, int maxiHeight){\n if(idx == n){\n return maxiHeight;\n }\n if(dp[idx][left] != -1){\n return dp[idx][left];\n }\n int...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
2
{ "code": "class Solution {\npublic:\n int MAXWIDTH;\n int t[1001][1001];\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth, int ind, int maxHeight)\n {\n if (ind>=books.size())\n return maxHeight;\n\n\n if(t[ind][shelfWidth] != -1) {\n return t[ind][shelfWidth]...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
2
{ "code": "class Solution {\npublic:\n int shelfWidth, n;\n int dp[1000][1001]; // dp[i][j] height for book i with layer Width_rem=j\n\n int f(int i, int Width_rem, int layerH, vector<vector<int>>& books) {\n if (i<0) return layerH; // Base case: no more books to place\n if (dp[i][Width_rem] !=...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
2
{ "code": "class Solution {\npublic:\n int dp[1007][1007];\n int solve(vector<vector<int>> &books,int idx,int remselfw,int h,int selfw){\n if(idx>=books.size())return h;\n if(dp[idx][remselfw]!=-1)return dp[idx][remselfw];\n int curbookw=books[idx][0];\n int curbookh=books[idx][1]...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n vector<vector<int>> _books;\n int maxWidthAllowed;\n int sz;\n unordered_map<string,int> dp;\npublic:\n int helper(int index, int curShelfWidth)\n {\n if (index >= _books.size())\n {\n return 0;\n }\n string key = to_string(index)+...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "int dp[1001][1001];\nclass Solution {\npublic:\n int f(vector<vector<int>>& arr, const int &t, int i, int curw, int curh){\n if(i == arr.size()){\n return dp[i][curw] = curh;\n }\n if(dp[i][curw] != -1) return dp[i][curw];\n\n auto w = arr[i][0], h = arr[i][1];\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int n,W;\n vector<vector<int>> arr;\n int dp[1000][1010];\n int rec(int i,int w,int h){\n if(i==n)return h;\n if(dp[i][w]!=-1)return dp[i][w];\n int ans=1e9;\n if(w-arr[i][0]>=0){\n ans=min(ans,rec(i+1,w-arr[i][0],max(h,arr[i][1...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int m[1001][1001] = {};\n \n int minHeightShelves(vector<vector<int>>& b, int max_w, int i = 0, int w = 0, int h = 0) {\n \n if (i == b.size())\n return h;\n \n if (m[i][w] == 0) // if not recorded in memorization\n {\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int m[1001][1001] = {};\n int minHeightShelves(vector<vector<int>>& b, int max_w, int i = 0, int w = 0, int h = 0) {\n if (i >= b.size()) \n return h;\n if (m[i][w] == 0) {\n m[i][w] = h + minHeightShelves(b, max_w, i + 1, b[i][0], b[i][...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int dp[1001][1001] = {0};\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth, int i = 0, int w = 0, int h = 0) \n {\n if(i >= books.size())\n return h;\n if(dp[i][w] == 0)\n {\n dp[i][w] = h + minHeightShelves(bo...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int m[1001][1001] = {};\n \n int minHeightShelves(vector<vector<int>>& b, int max_w, int i = 0, int w = 0, int h = 0) {\n \n if (i == b.size())\n return h;\n \n if (m[i][w] == 0) // if not recorded in memorization\n {\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int m[1001][1001] = {};\n \n int minHeightShelves(vector<vector<int>>& b, int max_w, int i = 0, int w = 0, int h = 0) {\n \n if (i == b.size())\n return h;\n \n if (m[i][w] == 0) // if not recorded in memorization\n {\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n // dp[i][remainingWidth] -> idx upto i and the remainingWidth of shelfWidth\n int numBooks = books.size();\n int dp[1001][1001];\n memset(dp, -1, sizeof(dp));\n\n auto dfs ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n \n int FindMinHeightRequired(int i, int curWidth, int maxHeight, int n, vector<vector<int>>&books, int shelfWidth, map<vector<int>, int>&mp)\n {\n if(i == n)return maxHeight;\n if(mp.find({i, curWidth, maxHeight}) != mp.end())\n {\n retur...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n vector<int> f (n, INT_MAX); // f[i]:放完前i个物品的最小书架高度\n\n f[0] = books[0][1];\n\n vector<int> ps (n);\n ps[0] = books[0][0];\n for (int i=1; i<n...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int N;\n map<vector<int>, int> dp;\n int fn(int at, int w, int h, vector<vector<int>>& books, int& sw) {\n if (at == N) return h;\n if (dp.find({at, w, h}) != dp.end()) return dp[{at, w, h}];\n int op1 = fn(at+1, books[at][0], books[at][1], books, s...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int dp(vector<vector<int>>& books,int shelfWidth,int i,unordered_map<int,int>& m){\n //cout<<i<<endl;\n if(m.find(i)!=m.end())\n return m[i];\n int h=books[i][1],w=shelfWidth-books[i][0],j=i+1;\n int t=INT_MAX;\n for(j=i+1;j<books...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n \n int f(vector<vector<int>> &books, int i, int curShelfWidth, int shelfWidth, int curMaxHeight, map<vector<int>, int> &dp) {\n \n if(i >= books.size()) return curMaxHeight;\n else if(dp.find({i, curShelfWidth, curMaxHeight}) != dp.end()) return dp[{i,...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n std::unordered_map<std::string, int> memo;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth, int curBook = 0, int curWidth = 0, int curHeight = 0) {\n \n if(curBook == books.size()) {\n return curHeight;\n }\n\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "const int MAX = 1e9; \n\nclass Solution {\n int shelfWidth;\n unordered_map<int, unordered_map<int, unordered_map<int, int>>> memo;\n\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n this->shelfWidth = shelfWidth;\n int mx...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n memset(dp, -1, sizeof(dp));\n return solve(books, shelfWidth, 0, shelfWidth, 0);\n }\n int solve(vector<vector<int>>& books, int width, int idx, int remWidth, int...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n memset(dp, -1, sizeof(dp));\n return solve(books, shelfWidth, 0, shelfWidth, 0);\n }\n int solve(vector<vector<int>>& books, int width, int idx, int remWidth, int...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n\nprivate: \n int dp[1005][1005];\npublic:\n\n\n int f(vector<vector<int>>& books, int shelfWidth, int i,\n int remainingShelfWidth, int maxHeight) {\n\n vector<int> currentBook = books[i];\n int maxHeightUpdated = max(maxHeight, currentBook[1]);\n\n if...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n unordered_map<int,unordered_map<int,unordered_map<int, int > > > cache;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n return minHeightShelvesRec(shelfWidth, 0, 0 , books, shelfWidth);\n }\n int minHeightShelvesRec(int remainingWidth, ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n unordered_map<int,unordered_map<int,unordered_map<int,int>>> mp;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n return solve(books,shelfWidth,0,0,0);\n }\n\n int solve(vector<vector<int>>& books,int shelfWidth,int idx,int prevWidth,int ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "#include<map>\n#include<vector>\n#include<cassert>\n\nusing namespace std;\n\nclass Solution {\n map<int, int> _f_memo = {};\n vector<vector<int>> _books;\n int _size;\n int _sw;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n _books = books;\n _...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n int minHeightShelvesInternal(const vector<vector<int>>& books, const int shelfWidth, const int shelfWidthLeft, const int idx, int currentHeight, map<pair<int,int>,int>& m){\n if (idx==books.size()) return currentHeight;\n pair<int,int> t {idx,shelfWidthLeft};\n if...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n struct pair_hash {\n inline std::size_t operator()(const std::pair<int,int> & v) const {\n return v.first*31+v.second;\n }\n };\n\n int helper(vector<vector<int>>& books, int pos, \n int shelfW, int curH, int curW, \n unordered_map...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n struct pair_hash {\n inline std::size_t operator()(const std::pair<int,int> & v) const {\n return v.first*31+v.second;\n }\n };\n\n int helper(vector<vector<int>>& books, int pos, \n int shelfW, int curH, int curW, \n unordered_map...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n map<pair<int,int>,int>mp;\npublic:\n int get(vector<vector<int>>& books, int i, int rem, int w, int mx){\n if(i >= books.size()){\n return mx;\n }\n if(mp.count({i,rem})){\n return mp[{i,rem}];\n }\n int ans = INT_MAX;\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int start = 0;\n unordered_map<int,unordered_map<int,unordered_map<int,int>>> dp;\n int f(int i,int width,int maxi,int &n,vector<vector<int>> &books) {\n \n if(dp[i][width].find(maxi) != dp[i][width].end()) {\n return dp[i][width][maxi];\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n map<pair<int,pair<int,int>>,int> dp;\n int solve(int in,int sum,int mx,vector<vector<int>>& books,int shelfwidth)\n {\n if(in >= books.size())\n return mx;\n pair<int,pair<int,int>> key = {in,{sum,mx}};\n if(dp.find(key)!=dp.end())\n r...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n struct hash_pair {\n template <class T1, class T2>\n std::size_t operator () (const std::pair<T1,T2>& p) const {\n auto h1 = std::hash<T1>{}(p.first);\n auto h2 = std::hash<T2>{}(p.second);\n return h1 ^ h2; // Combine hash value...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n\n map<pair<int,pair<int,int>>,int> m;\n int dfs(int index, vector<vector<int>>& books, int& shelfWidth,int mw,int mh){\n if(m[{index,{mw,mh}}]==0){\n if(index==books.size()){\n m[{index,{mw,mh}}]=mh;\n }\n else if(book...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int DP(int i , int rem ,int currH, vector<vector<int>>& books, int shelfWidth ,vector<map<pair<int,int>,int>>& dp){\n if(i==books.size()) return currH;\n if(dp[i].count({rem,currH})) return dp[i][{rem,currH}];\n int & ret = dp[i][{rem,currH}];\n re...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n map<pair<int, int>, int> set;\nprivate:\n int minHeightShelvesCheck(vector<vector<int>> &books, int &shelfWidth, int currWidth, int currHeight, int index){\n int result;\n int width = books[index][0];\n int height = books[index][1];\n \n if(index ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int rows = books.size();\n int cols = shelfWidth + 1;\n std::vector<int> memo(rows * cols, -1);\n\n std::function<int(int, int)> helper = [&](int index, int freeShelfWidth) -> int...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n vector<vector<int>> books;\n int shelfWidth;\n map<pair<int,int>, int> memoMap;\n int dfs(int curIndex, int curShelfLeftOverWidth, int maxHeightInCurShelf)\n {\n if(curIndex >= books.size())\n return maxHeightInCurShelf;\n auto key = make...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "\nint dp[1002][1002][2];\n\nint find(int pos, int start, int cw, int mx, int stat, vector<vector<int>> &b, int sw)\n{\n\n if(pos == b.size())\n return mx;\n\n if(dp[pos][start][stat] != -1)\n return dp[pos][start][stat];\n\n int ans = 1e9;\n\n int w = b[pos][0];\n int h = b[pos...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n map<pair<int,int>,int> mp;\n int solve(vector<vector<int>>& books, int sw, int h, int i, int rw) {\n if(i>=books.size())\n return h;\n int dp1=1e9,dp2=1e9;\n if(mp.count({i,rw}))\n return mp[{i,rw}];\n if(books[i][0]<=rw) {...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "static const auto setup = []()\n{\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n cout.tie(NULL);\n return 'c';\n}();\nclass Solution {\npublic:\n int DP(vector<vector<int>>& books, map<pair<int,int> , int>& dp ,int shelfWidth , int i , int height , int width)\n {\n if(i>=books....
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int W;\n map<pair<int, int>, int> dp;\n int min_h(vector<vector<int>>& books, int s, int h, int w) {\n int maxH = max(books[s][1], h);\n\n if (s == books.size() - 1) {\n if (w + books[s][0] <= W) {\n return maxH;\n }\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int W) {\n int n = books.size();\n map<pair<int, pair<int, int>>, int> memo;\n function<int(int, int, int)> f = [&](int i, int h, int left) {\n if (i >= n) return 0;\n assert(left >= 0...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int W) {\n int n = books.size();\n map<pair<int, pair<int, int>>, int> memo;\n function<int(int, int, int)> f = [&](int i, int h, int left) {\n if (i >= n) return 0;\n assert(left >= 0...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n int n;\n int t[1001][1001]={-1}; \n // use simple concept of keeping book at same shelf or next shelf \n // recursive approach so using mwmoization works well here\n int solve(vector<vector<int>>& books,int rem_width,int shelfWidth,int i,int max_height){\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n int n;\n int t[1001][1001]={-1}; \n // use simple concept of keeping book at same shelf or next shelf \n // recursive approach so using mwmoization works well here\n int solve(vector<vector<int>>& books,int rem_width,int shelfWidth,int i,int max_height){\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n unordered_map<int,unordered_map<int,unordered_map<int, int > > > cache;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n return minHeightShelvesRec(shelfWidth, 0, 0 , books, shelfWidth);\n }\n int minHeightShelvesRec(int remainingWidth, ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n unordered_map<int,unordered_map<int,unordered_map<int, int > > > cache;\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n return minHeightShelvesRec(shelfWidth, 0, 0 , books, shelfWidth);\n }\n int minHeightShelvesRec(int remainingWidth, ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "#include <vector>\n#include <unordered_map>\n#include <utility>\n#include <functional>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n\n struct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& p) const {\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n#define ll long long\nll dp[1001][1001]; \n\tll solve(vector<vector<int>> &books, int i, int remShelfWidth, int maxShelfHeight, \n\t\t\t int shelfWidth) {\n\n\t\tif(i == books.size()) {\n\t\t\treturn maxShelfHeight;\n\t\t}\n if(dp[remShelfWidth][i]!=-1) return dp[remShe...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int inf = 1e9;\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n pair<int, int> dp[n+1][shelfWidth+1];\n for (int i = 0; i <= n; i++)\n for (int j = 0; j <= shelfWidth; j++) \n dp[i...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int n;\n unordered_map<string,int>mp;\n int func(int i,int currwidth,int prevHeight,vector<vector<int>>& books, int shelfwidth){\n if(i>=n)return prevHeight;\n string temp=to_string(i)+\" \"+to_string(currwidth)+\" \"+to_string(prevHeight);\n if(mp....
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n long long dp[1004][1004];\n int width;\n int n;\n long long solve(int indx,int w,int hght,vector<vector<int>>& books){\n if(indx==n){\n return hght;\n }\n long long &ret = dp[indx][w];\n if(~ret)\n return ret;\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int n, shelfWidth;\n int minHeightShelves(vector<vector<int>>& books, int _shelfWidth) {\n n = books.size();\n shelfWidth = _shelfWidth;\n vector<vector<int>> dp(n, vector<int>(shelfWidth+1, -1));\n\n return recur(0, books, shelfWidth, 0, dp);\n...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n int solve(int i, vector<vector<int>>& books, int &d, int height, int remWidth, vector<vector<int>> &dp){\n if(i == books.size()) return height;\n if(dp[i][remWidth] != -1) return dp[i][remWidth];\n\n int notTake = solve(i+1, books, d, books[i][1], d-books[i][0], d...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int fun(int ind,vector<vector<int>>& books,int remwidth, int shelfWidth,int maxHeight,vector<vector<int>>&dp)\n {\n if(ind>=books.size()) return maxHeight;\n\n int keep=1e9,skip=1e9;\n int bookthickness=books[ind][0];\n int bookheight=books[ind]...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n vector<vector<int>> dp(n, vector<int>(shelfWidth + 1, -1)); \n return solve(0, books, shelfWidth, shelfWidth, 0, dp);\n }\n\n int solve(int i, vector<vector...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n vector<vector<int>> dp(n, vector<int>(shelfWidth + 1, -1)); \n return solve(0, books, shelfWidth, shelfWidth, 0, dp);\n }\n\n int solve(int i, vector<vector...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int solve(int index,int width,int height,vector<vector<int>>&books,int originalwidth, vector<vector<int>>&dp){\n if(index>=books.size()){\n return height;\n }\n //\n if(dp[index][width]!=-1)\n return dp[index][width];\n int...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n vector<vector<int>> book;\n\n int new_or_curr(int i, int remain_space, int prev_shelf_heigh, int shelf_w){\n \n if(i==book.size()){ // all books are placed\n return prev_shelf_heigh;\n }\n \n if(dp[...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n vector<vector<int>> book, dp;\n int shelf;\n int f(int idx, int remainWidth, int maxHeight){\n if(remainWidth < 0)return 1e9 + 7;\n int n = book.size();\n if(idx == n)return 0;\n if(idx == n-1){\n if(remainWidth >= book[idx][0])re...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\nprivate:\n vector<vector<int>> dp;\n vector<vector<int>> books;\n int shelfWidth;\n int solution(int idx,int leftW,int maxH){\n if(idx==books.size()) return maxH;\n int currMax = max(maxH,books[idx][1]);\n if(dp[idx][leftW]!=-1) return dp[idx][leftW];\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n map<string, int> mp;\n int helper(vector<vector<int>> &books,int maxHeight, int mw, int sum, int i) {\n if(i >= books.size()) return maxHeight;\n int take = 10000000, leave =10000000;\n string t = \"H\"+ to_string(maxHeight) + \"S\"+ to_string(sum) + \...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic: \n vector<vector<int>> memo;\n \n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n int n = books.size();\n memo = vector<vector<int>>(n, std::vector<int>(shelfWidth + 1, -1));\n return solve(books, shelfWidth, 0, 0, 0);\n ...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int helper(vector<vector<int>>& books, int &shelfWidth, int currWidth, int maxHeight, int i) {\n if(i >= books.size()) {\n return maxHeight;\n }\n \n int w = books[i][0], h = books[i][1];\n \n int a...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int helper(vector<vector<int>>& books, int &shelfWidth, int currWidth, int maxHeight, int i) {\n // base condition : if no more books remain, return max height of current lvl\n if(i >= books.size()) {\n return maxHeight;\n...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& books, int shelfWidth, vector<vector<int>>& dp, int i, int remWidth, int maxHeight) {\n if (i == books.size()) {\n return maxHeight;\n }\n \n if (dp[i][remWidth] != 0) {\n return dp[i][remWidth];...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\n int W ;\npublic:\n int solution(vector<vector<int>>&books, int i, int &maxHeight, int shelfWidth, vector<vector<int>>&dp){\n if(i==books.size()){\n return maxHeight; \n }\n int placeThisShelf = 1e9, GoToNextShelf= 1e9;\n int max_initial = 0;\n...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n vector<vector<int>> memo(books.size(), vector<int>(shelfWidth + 1, 0));\n return dpHelper(books, shelfWidth, memo, 0, shelfWidth, 0);\n }\n\nprivate:\n int dpHelper(vector<vector<int>>& b...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n vector<vector<int>> memo(books.size(), vector<int>(shelfWidth + 1, 0));\n return dpHelper(books, shelfWidth, memo, 0, shelfWidth, 0);\n }\n\nprivate:\n int dpHelper(vector<vector<int>>& b...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n\n int helper(int i, vector<vector<int>> &books,int shelve,int shelfWidth,vector<vector<int>> &dp){\n int n = books.size();\n if(i >= n){\n return 0;\n }\n if(dp[i][shelve] != -1){\n return dp[i][shelve];\n }\n in...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n vector<vector<int>> memo(books.size(), vector<int>(shelfWidth + 1, 0));\n return dpHelper(books, shelfWidth, memo, 0, shelfWidth, 0);\n }\n\nprivate:\n int dpHelper(vector<vector<int>>& b...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "/*\n\nstart time: 7:17\n\npost-notes:\n-accepted 7:53 but bad on time and memory\n\nis the minimum just obtained by cramming as many books into each shelf as is possible?\ni think so. because adding another shelf always increases height by more than not\n\ndamn no that's not true\n\nso i guess dp then in t...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n vector<vector<int>> memo(books.size(), vector<int>(shelfWidth + 1, 0));\n return dpHelper(books, shelfWidth, memo, 0, shelfWidth, 0);\n }\n\nprivate:\n int dpHelper(vector<vector<int>>& b...
1,196
<p>You are given an array <code>books</code> where <code>books[i] = [thickness<sub>i</sub>, height<sub>i</sub>]</code> indicates the thickness and height of the <code>i<sup>th</sup></code> book. You are also given an integer <code>shelfWidth</code>.</p> <p>We want to place these books in order onto bookcase shelves th...
3
{ "code": "class Solution {\npublic:\n int minHeightShelves(vector<vector<int>>& books, int shelfWidth) {\n auto cache = std::vector<std::vector<int>>(\n books.size(),\n std::vector<int>(books.size(), INVALID)\n );\n return Dp(books, shelfWidth, 0, 0, 0, 0, cache);\n }...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/* Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *ri...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/* Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *ri...
1,207
<p>Given the <code>root</code> of a binary tree, each node in the tree has a distinct value.</p> <p>After deleting all nodes with a value in <code>to_delete</code>, we are left with a forest (a disjoint union of trees).</p> <p>Return the roots of the trees in the remaining forest. You may return the result in any ord...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...