id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
3
{ "code": "class Solution {\n\npublic:\n TreeNode* createBinaryTree(vector<vector<int>>& arr) {\n \n map<int, TreeNode*> nodes;\n map<int, int> childcheck;\n set<int> totalnodes;\n for(auto vec : arr){\n \n int par = vec[0], child = vec[1], isleft = vec[2];\...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
3
{ "code": "class Solution {\npublic:\n TreeNode* createBinaryTree(vector<vector<int>>& descriptions) {\n // Sets to track unique children and parents\n unordered_set<int> children, parents;\n // Map to store parent to children relationships\n unordered_map<int, vector<pair<int, int>>> p...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
2,306
<p>You are given a 2D integer array <code>descriptions</code> where <code>descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>]</code> indicates that <code>parent<sub>i</sub></code> is the <strong>parent</strong> of <code>child<sub>i</sub></code> in a <strong>binary</strong> tree of <strong>uniq...
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...
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
0
{ "code": "const unordered_set<string> st {\n \"1\", \"3\", \"9\", \"27\", \"81\", \"243\", \"729\", \"2187\", \"6561\", \"19683\", \"59049\", \"177147\", \"531441\", \"1594323\", \"4782969\", \"14348907\", \"43046721\", \"129140163\", \"387420489\", \"1162261467\"\n };\nclass Solution {\npublic:\n ...
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
0
{ "code": "const unordered_set<string> st {\n \"1\", \"3\", \"9\", \"27\", \"81\", \"243\", \"729\", \"2187\", \"6561\", \"19683\", \"59049\", \"177147\", \"531441\", \"1594323\", \"4782969\", \"14348907\", \"43046721\", \"129140163\", \"387420489\", \"1162261467\"\n };\nclass Solution {\npublic:\n ...
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
0
{ "code": "const unordered_set<string> st {\n \"1\", \"3\", \"9\", \"27\", \"81\", \"243\", \"729\", \"2187\", \"6561\", \"19683\", \"59049\", \"177147\", \"531441\", \"1594323\", \"4782969\", \"14348907\", \"43046721\", \"129140163\", \"387420489\", \"1162261467\"\n };\nclass Solution {\npublic:\n ...
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
0
{ "code": "class Solution {\npublic:\n bool isPowerOfThree(int n) {\n if(n==0) return false;\nwhile(1){\n if(n==1|| n==3) return true;\n if(n%3!=0) return false;\n n /=3;\n}\n return true;;}\n};", "memory": "8100" }
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
0
{ "code": "class Solution {\npublic:\n \n bool isPowerOfThree(int n) {\n if(n==1){\n return true;\n }\n if(n==0 || n%3!=0){\n return false;\n }\n return isPowerOfThree(n/3);\n }\n};", "memory": "8200" }
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
2
{ "code": "class Solution {\npublic:\n bool isPowerOfThree(int n) {\n if(n==0)\n {\n return false;\n }\n if(n==1)\n {\n return true;\n }\n else\n {\n if(n%3==0)\n {\n return isPowerOfThree(n/3);\n ...
326
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p>&nbsp;</p> <p><strong class="example"...
2
{ "code": "class Solution {\npublic:\n bool isPowerOfThree(int n) {\n for (int i = 0; i < 31; i++) {\n long long pow = powl(3, i);\n if (pow == n) {\n return true;\n }\n }\n return false;\n \n }\n};", "memory": "8600" }
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "static std::vector<int> odds;\nstatic std::vector<int> evens;\n/// This is definately cheating it exits before the function. \nint thisIsStupid = []{\n\n char ch;\n ofstream ans(\"user.out\");\n while (std::cin >> ch) {\n ch = getchar();\n odds.clear();\n evens.clear();\n ...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "static std::vector<int> odds;\nstatic std::vector<int> evens;\n/// This is definately cheating it exits before the function. \nint thisIsStupid = []{\n\n char ch;\n ofstream ans(\"user.out\");\n while (std::cin >> ch) {\n ch = getchar();\n odds.clear();\n evens.clear();\n ...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic std::vector<int> odd...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "class Solution {\npublic:\n ListNode* oddEvenList(ListNode* head) {\n if (!head || !head->next) return head;\n\n ListNode* odd = head;\n ListNode* even = head->next;\n ListNode* evenHead = even;\n\n while (even && even->next) {\n odd->next = even->next;\n ...
328
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p> <p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "class Solution {\npublic:\nint m, n;\n short path[200][200];\nint dfs(int i, int j, vector<vector<int>>& mat) {\n if(path[i][j] > 0) return path[i][j];\n if(path[i][j] == -1) return 0;\n int max_next = 0;\n path[i][j] = -1;\n if(i > 0 && mat[i][j] < mat[i-1][j]) ma...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "class Solution {\npublic:\n\n int dp[201][201];\n int fun(int x,int y,vector<vector<int>>& arr){\n int n = arr.size(); \n int m = arr[0].size();\n\n if( dp[x][y] != -1 )return dp[x][y];\n\n int maxi = 0;\n if( x+1 < n && arr[x][y] > arr[x+1][y] )maxi = fun(x+1,y,arr...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "class Solution {\n int dp[201][201];\n int dfs(int r, int c, int par, vector<vector<int>>&matrix) {\n int dir[] = {0, -1, 0, 1, 0};\n int len = 1;\n if(dp[r][c] != -1) return dp[r][c];\n\n for(int k=0; k<4; ++k) {\n int nr = r + dir[k];\n int nc = c +...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "class Solution {\npublic:\n bool isValid(int i, int j, vector<vector<int>>& matrix, int px, int py){\n if(i<0 || j<0 || i>=matrix.size() || j>=matrix[0].size() || matrix[i][j]<=matrix[px][py])\n return false;\n return true;\n }\n int memo[202][202];\n int dping(int i, i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "class Solution {\npublic:\n int func(int i, int j, vector<vector<int>>& mat, vector<vector<int>>& dp) {\n if(dp[i][j] != -1) return dp[i][j];\n\n int dx[4] = {1,0,-1,0};\n int dy[4] = {0,1,0,-1};\n\n int ans = 1;\n\n for(int k = 0; k<4; k++){\n int nx = i + ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
0
{ "code": "\n\nclass Solution {\npublic:\n int ans=0;\n vector<vector<int>> dp;\n\n int dfs(int i,int j,vector<vector<int>>& matrix,int& n,int& m){\n int res=1;\n if(dp[i][j]!=-1) return dp[i][j];\n \n int x[] = { -1 , 1 , 0 , 0 };\n int y[] = { 0 , 0 , -1 , 1 };\n\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\nint count(int i,int j,int row,int col,int prevVal,vector<vector<int>>& matrix,vector<vector<int>> &dp){\n if(i<0 || i>=row || j<0 || j>=col || matrix[i][j]<=prevVal)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n int up=1+count(i-1,j,row,col,matrix[i][j],matrix,dp);\n int ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\n int x[4]={0,0,1,-1};\n int y[4]={1,-1,0,0};\n vector<vector<int>>dp;\n int dfs(vector<vector<int>>& matrix,int r,int c,int m,int n){\n if(dp[r][c]!=-1){\n return dp[r][c];\n }\n int ans=0;\n for(int i=0;i<4;i++){\n in...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\n\n int longestIncreasingPathHelper(\n const vector<vector<int>>& matrix, \n const int &height, \n const int &width, \n int currX, \n int currY, \n vector<bool> &used,\n //map<pair<int, int>, int> &pathLengthMap\n vector<i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\n\n int longestIncreasingPathHelper(\n const vector<vector<int>>& matrix, \n const int &height, \n const int &width, \n int currX, \n int currY, \n vector<bool> &used,\n //map<pair<int, int>, int> &pathLengthMap\n vector<i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\n int h;\n int w;\n vector<vector<int>> dp;\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n h = matrix.size();\n w = matrix[0].size();\n int globalMax = INT_MIN;\n dp.assign(h, vector<int>(w, -1));\n for(int row=0; row<h;...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
2
{ "code": "class Solution {\npublic:\n int dfs(vector<vector<int>>& matrix, vector<vector<int>> &visited, vector<vector<int>> &lp, int x1, int y1){\n visited[x1][y1]=1;\n lp[x1][y1]=1;\n for(int i=x1-1;i<=x1+1;i++){\n for(int j=y1-1; j<=y1+1; j++){\n if(i<0 || j<0 || ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<int>dx{0,0,-1,1};\n vector<int>dy{1,-1,0,0};\n int n;\n int m;\n bool isValid(int x, int y){\n return (x >= 0 && x < n && y >= 0 && y < m);\n }\n int solve(vector<vector<int>>&matrix, vector<vector<int>>&dp, vector<vector<bool>>&vis, int x, int...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int row[4] = {0,0,-1,1};\n int col[4] = {1,-1,0,0};\n\n bool valid(int i, int j, int n, int m){\n return i>=0 && j>=0 && i<n && j<m;\n }\n\n int dfs(vector<vector<int>>& matrix, int i, int j, int n, int m, vector<vector<bool>> &visited, vector<vector<int>> ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dfs(int i,int j,vector<vector<int>>& matrix,vector<vector<int>>& dp,vector<vector<int>>& visited){\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n if(visited[i][j]==1){\n return 0;\n }\n \n visited[i][j]=1;\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution\n{\n bool isInMatrix(int rowCnt, int colCnt, int row, int col)\n {\n return 0 <= row && row < rowCnt \n && 0 <= col && col < colCnt;\n }\n\n bool hasEdge(const vector<vector<int>>& matrix, int fromRow, int fromCol, int toRow, int toCol)\n {\n return ma...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\nint mod=1e9+7;\nint dp[1001][1001];\nvector<int>delr={-1,0,1,0};\nvector<int>delc={0,1,0,-1};\nvector<vector<int>>v;\nint n,m;\nint dfs(int i,int j){\n int r=1;\n if(dp[i][j]!=-1) return dp[i][j];\n for(int l=0; l<4; l++){\n int nr=i+delr[l];\n int nc=j+del...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n vector<pair<int, int>> pos;\n for (int i = 0; i<matrix.size(); i++) {\n for (int j = 0; j<matrix[i].size(); j++) {\n pos.emplace_back(i, j);\n }\n }\n s...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n\n vector<pair<int, int>> allCoords;\n for (uint i = 0; i < m; ++i){\n for (uint j = 0; j < n; ++j){\n allCoord...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n std::vector<std::vector<int>> lp(m, std::vector<int>(n, 1));\n std::deque<std::tuple<int, int, int>> flat {};\n\n for (int i = 0;...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "#define db(x) cout<<#x<<\" \"<<x<<endl;\nclass Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n // tao canh: (i,j) -> (x,y): neu a[i][j]<a[x][y]\n // can tim topo sort va khoang cach dai nhat\n int n=matrix.size(), m=matrix[0].size();\n vector<...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "// phat hien chu ki va tim topo sort\n// https://leetcode.com/problems/course-schedule-ii/description/\n\n#define db(x) cout<<#x<<\" \"<<x<<endl;\nclass Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n // tao canh: (i,j) -> (x,y): neu a[i][j]<a[x][y]\n // ca...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n\n int height = 0;\n if(matrix.empty()) {\n return height;\n }\n \n int numRows = matrix.size();\n int numCols = matrix[0].size();\n std::vector<std::vector<i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n \n\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> dp(n,vector<int>(m,1));\n priority_queue<pair<int,pair<int,int>>>pq;\n for(int i =0;i<n;i++){\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\tint longestIncreasingPath(vector<vector<int>>& b) {\n\t\tint n = b.size(), m = b[0].size();\n\t\tvector<vector<int>> a(n + 2, vector<int>(m + 2)), c;\n\t\tc = a;\n\t\tvector<pair<int, int>> it;\n\t\tit.reserve(n * m);\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n int m,n;\npublic:\n void solve(int i,int j,int s,int prev,vector<vector<int>>& matrix,vector<vector<int>>& ans){\n if(i>=0 && i<m && j>=0 && j<n && matrix[i][j]>prev){\n ans[i][j] = max(ans[i][j],s);\n }\n }\n int longestIncreasingPath(vector<vector<i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "struct Node {\n int i;\n int j;\n int v;\n};\nbool comparator(const Node &n1, const Node &n2) {\n return n1.v > n2.v;\n}\n\nclass Solution {\npublic:\n vector<vector<int>> neighbor = {\n {0, 1}, {0, -1}, {-1, 0}, {1, 0}\n };\n bool inside(int i, int j, int m, int n) {\n r...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n map<int, vector<pair<int, int>>> values;\n \n int h = matrix.size();\n int w = matrix[0].size();\n\n for (auto i = 0; i < h; ++i) {\n auto& line = matrix[i];\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\nprivate:\n vector<int> dirs_x = {0, -1, 0, 1};\n vector<int> dirs_y = {-1, 0, 1, 0};\n bool isValid(int row, int col, int n, int m) {\n if (row>=0 and row<n and col>=0 and col<m) return true;\n return false;\n }\npublic:\n int longestIncreasingPath(vector<vect...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n vector<pair<int,pair<int,int>>> v;\n vector<vector<int>> visit;\n for (int i = 0; i < matrix.size(); i ++) {\n visit.push_back({});\n for (int j = 0; j < matrix[i].size(); j ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dfs(int i, int j, vector<vector<int>>& matrix, vector<vector<int>>& dp, int& n, int& m) {\n if (dp[i][j] != -1) return dp[i][j];\n vector<pair<int, int>> directions = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\n int maxLength = 1; \n for (auto dir : ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n if(matrix.empty()||matrix[0].empty()) return 0;\n int m=matrix.size(), n=matrix[0].size(), res=0;\n vector<vector<int>> len(m, vector<int>(n));\n for(int i=0; i<m; ++i) {\n for(i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n map<pair<int, int>, int>mp;\n vector<int>dx={1, 0, -1, 0}, dy={0, 1, 0, -1};\n vector<vector<int>>vis;\n int m, n;\n int dfs(int x, int y, vector<vector<int>>& grid){\n // vis[x][y]=1;\n int ans=1, val=0;\n if(mp.find({x, y})!=mp.end()) return...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "map<pair<int,int>, int> mp;\nclass Solution {\npublic:\n bool validPoint(pair<int,int> p, int m, int n) {\n if(p.first >=0 && p.first<m && p.second>=0 && p.second<n) {\n return true;\n }\n return false;\n }\n bool validPath(vector<vector<int>>& matrix, pair<int,int>...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int check(vector<vector<int>>& matrix, int i, int j, int prev, map<pair<int, int>, int>& dp){\n int n = matrix.size();\n int m = matrix[0].size();\n if(i >= n || j >= m || i < 0 || j < 0 || matrix[i][j] <= prev) return 0;\n if(dp.find({i, j}) != dp...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<vector<int>> memo(m, vector<int>(n, 0));\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n\n int result = 0;\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "/*\n Given matrix, return length of longest increasing path\n Ex. matrix = [[9,9,4],[6,6,8],[2,1,1]] -> 4, [1,2,6,9]\n\n DFS + memo, cache on indices, compare to prev for increasing check\n\n Time: O(m x n)\n Space: O(m x n)\n*/\n\nclass Solution {\npublic:\n int longestIncreasingPath(vec...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n vector<vector<int>> matrix;\n int n, m;\n\n bool isValid(int i, int j) {\n return i >= 0 && j >= 0 && i < n && j < m;\n }\n\n int dfs(int i, int j) {\n if (dp[i][j] != 0) return dp[i][j]; // Return cached result\n\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n if(m == 0) return 0;\n int n = matrix[0].size();\n vector<vector<int>> memo(m, vector<int>(n, -1));\n int max_len = 0;\n \n for(int r = 0; r < ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "/*\n * @lc app=leetcode id=329 lang=cpp\n *\n * [329] Longest Increasing Path in a Matrix\n */\n\n// @lc code=start\nclass Solution {\npublic:\n int dfs(vector<vector<int>>& matrix, int i, int j, int rows, int columns, vector<vector<int>>&memo){\n if(memo[i][j] != -1){\n return memo[i]...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int maxPath = 1;\n vector<vector<int>> visitedAmount(matrix.size(), vector<int>(matrix[0].size(), 0));\n priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, less<tuple<int, int, int...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int maxPath = 1;\n vector<vector<int>> visitedAmount(matrix.size(), vector<int>(matrix[0].size(), 0));\n priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, less<tuple<int, int, int...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n vector<vector<int>> memo;\n int compute(vector<vector<int>> &matrix, int i, int j) {\n if(i >= memo.size() || j >= memo[0].size()) return 0;\n if(memo[i][j] != -1) return memo[i][j];\n vector<int> ans;\n if(i+1 < memo.size() && matrix[i+1][j] > matrix[i]...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n int longestIncreasingPathHelper(\n const vector<vector<int>>& matrix, \n const int &height, \n const int &width, \n int currX, \n int currY, \n vector<bool> &used,\n map<pair<int, int>, int> &pathLengthMap\n ) \n {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n void init_matrix(vector<vector<int>>& m) {\n for (int i = 0; i < row_cnt; ++i) {\n\n m.push_back(vector<int>{});\n for (int j = 0; j < col_cnt; ++j)\n m[i].push_back(-1);\n }\n }\n int longestIncreasingPath(vector<vecto...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<int> delx={1,0,-1,0};\n vector<int> dely={0,1,0,-1};\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n=matrix.size();\n int m=matrix[0].size();\n vector<vector<int>> graph(n*m+1,vector<int>());\n vector<int> indegree(n...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "typedef long long ll;\nclass Solution {\n\nll dfs(ll vertex, vector<vector<ll>> &adj, vector<ll> &dp){\n if(dp[vertex] != -1)\n return dp[vertex];\n ll x = 0; \n for (auto child : adj[vertex]){\n ll y = dfs(child, adj, dp);\n x = max(x, y);\n }\n return dp[vertex] = x+1...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n const int n_rows = matrix.size();\n const int n_cols = matrix[0].size();\n \n const int dr[] = {-1, 1, 0, 0};\n const int dc[] = {0, 0, -1, 1};\n\n // create graph\n st...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n int maxLength = 1;\n\npublic:\n void addEdge(vector<vector<int>> &e, vector<vector<int>> &m,\n int x1, int y1, int x2, int y2,\n vector<int> &in, vector<int> &out) {\n\n int k = m[0].size();\n\n if (m[x1][y1] < m[x2][y2]) {\n ...