leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit4f3f21b33b22554b5b0901b97eab1d5d9cf191ce
parent6ef789ff3665ea452c124eff0020a06243a932fe
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateMon, 2 Jan 2023 23:58:41 +0100

20 Graph problems

Diffstat:
AProblems/0129.cpp|
AProblems/0207.cpp|+++++++++++++++++++++++++++
AProblems/0210.cpp|++++++++++++++++++++++++++++
AProblems/0399.cpp|+++++++++++++++++++++++++++++++++++++++++++++++
AProblems/0520.cpp|+++++++++
AProblems/0743.cpp|++++++++++++++++++++++++++++++
AProblems/0785.cpp|+++++++++++++++++++++++++
AProblems/0990.cpp|+++++++++++++++++++++++++++++++++++
AProblems/1202.cpp|++++++++++++++++++++++++++++++++++++++++++
AProblems/1311.cpp|+++++++++++++++++++++++++++++++++++++
AProblems/1334.cpp|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AProblems/1361.cpp|+++++++++++++++++++++++++++++++++++++++++++++++++++
AProblems/1514.cpp|+++++++++++++++++++++++++++++++++++++++++
AProblems/1786.cpp|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AProblems/2039.cpp|+++++++++++++++++++++++++++++++
AProblems/2101.cpp|++++++++++++++++++++++++++++++++++++
AProblems/2115.cpp|+++++++++++++++++++++++++++++++++++++++++++++++
AProblems/2192.cpp|++++++++++++++++++++++++
AProblems/2374.cpp|+++++++++++++++++++
AProblems/2477.cpp|+++++++++++++++++++++++++++++++++
AProblems/2492.cpp|++++++++++++++++++++++++++++++++++++
MREADME.md|+++++++++++++++++++++++++++++++++++++++++++---------------------------------------

22 files changed, 988 insertions(+), 233 deletions(-)


diff --git a/Problems/0129.cpp b/Problems/0129.cpp

diff --git a/Problems/0207.cpp b/Problems/0207.cpp

@@ -0,0 +1,27 @@

class Solution {
public:
bool canFinish(int n, vector<vector<int>> &prerequisites) {
vector<vector<int>> adj(n);
vector<int> count(n, 0);
int num = 0;
for (auto &p : prerequisites) {
adj[p[0]].push_back(p[1]);
count[p[1]]++;
}
queue<int> q;
for (int i = 0; i < n; i++)
if (!count[i]) q.push(i);
while (!q.empty()) {
int root = q.front();
q.pop();
n--;
for (int c : adj[root])
if (!--count[c]) q.push(c);
}
return n == 0;
}
};

diff --git a/Problems/0210.cpp b/Problems/0210.cpp

@@ -0,0 +1,28 @@

class Solution {
public:
vector<int> findOrder(int n, vector<vector<int>> &prerequisites) {
vector<vector<int>> adj(n);
vector<int> count(n, 0);
vector<int> res;
int num = 0;
for (auto &p : prerequisites) {
adj[p[1]].push_back(p[0]);
count[p[0]]++;
}
queue<int> q;
for (int i = 0; i < n; i++)
if (!count[i]) q.push(i);
while (!q.empty()) {
int root = q.front();
q.pop();
res.push_back(root);
n--;
for (int c : adj[root])
if (!--count[c]) q.push(c);
}
return n == 0 ? res : vector<int>();
}
};

diff --git a/Problems/0399.cpp b/Problems/0399.cpp

@@ -0,0 +1,47 @@

class Solution {
const int SIZE = 26 * 5;
int hash(const string &st) {
static int index = 0;
static unordered_map<string, int> um;
if (!um.count(st)) um[st] = index++;
return um[st];
}
double dfs(vector<vector<pair<int, double>>> &adj, int start, int goal) {
stack<pair<int, double>> st;
vector<bool> visited(SIZE, false);
st.push({start, 1});
visited[start] = true;
while (!st.empty()) {
auto [root, value] = st.top();
st.pop();
if (root == goal) return value;
visited[root] = true;
for (auto &v : adj[root])
if (!visited[v.first]) st.push({v.first, value * v.second});
}
return -1;
}
public:
vector<double> calcEquation(vector<vector<string>> &equations,
vector<double> &values,
vector<vector<string>> &queries) {
vector<vector<pair<int, double>>> adj(SIZE, vector<pair<int, double>>());
for (int i = 0; i < values.size(); i++) {
adj[hash(equations[i][0])].push_back({hash(equations[i][1]), values[i]});
adj[hash(equations[i][1])].push_back(
{hash(equations[i][0]), 1 / values[i]});
}
vector<double> res(queries.size(), -1);
for (int i = 0; i < queries.size(); i++) {
int start = hash(queries[i][0]), goal = hash(queries[i][1]);
if (adj[start].empty() || adj[goal].empty()) continue;
res[i] = dfs(adj, start, goal);
}
return res;
}
};

diff --git a/Problems/0520.cpp b/Problems/0520.cpp

@@ -0,0 +1,9 @@

class Solution {
public:
bool detectCapitalUse(string word) {
int count = 0;
for (char &c : word) count += c == toupper(c);
return count == 0 || count == word.size() ||
(count == 1 && word[0] == toupper(word[0]));
}
};

diff --git a/Problems/0743.cpp b/Problems/0743.cpp

@@ -0,0 +1,30 @@

class Solution {
struct edge {
int dest, time;
edge(int dest, int time) : dest(dest), time(time) {}
friend bool operator<(const edge &s1, const edge &s2) {
return s1.time > s2.time;
}
};
public:
int networkDelayTime(vector<vector<int>> &times, int n, int k) {
vector<vector<edge>> adj(n + 1, vector<edge>());
for (auto &p : times) adj[p[0]].push_back({p[1], p[2]});
priority_queue<edge> st;
st.push({k, 0});
unordered_set<int> us;
int time = 0;
while (!st.empty()) {
auto [root, t] = st.top();
st.pop();
if (us.count(root)) continue;
time = t;
us.insert(root);
for (auto &p : adj[root])
if (!us.count(p.dest)) st.push({p.dest, t + p.time});
}
return us.size() == n ? time : -1;
}
};

diff --git a/Problems/0785.cpp b/Problems/0785.cpp

@@ -0,0 +1,25 @@

class Solution {
public:
bool isBipartite(vector<vector<int>> &graph) {
int n = graph.size();
vector<int> color(n, 0);
for (int i = 0; i < n; i++) {
if (color[i]) continue;
stack<int> st;
st.push(i), color[i] = 1;
while (!st.empty()) {
int root = st.top();
st.pop();
for (int c : graph[root]) {
if (color[root] == color[c]) return false;
if (!color[c]) {
st.push(c);
color[c] = -color[root];
}
}
}
}
return true;
}
};

diff --git a/Problems/0990.cpp b/Problems/0990.cpp

@@ -0,0 +1,35 @@

class UnionFind {
vector<int> root, rank;
public:
UnionFind(int n) : root(n), rank(n, 1) { iota(root.begin(), root.end(), 0); }
int find(int x) {
if (x == root[x]) return x;
return root[x] = find(root[x]);
}
void join(int x, int y) {
x = find(x), y = find(y);
if (x != y) {
if (rank[x] > rank[y]) swap(x, y);
root[y] = x;
rank[x] += x == y;
}
}
};
class Solution {
public:
bool equationsPossible(vector<string> &equations) {
UnionFind uf(26);
for (auto &s : equations)
if (s[1] == '=') uf.join(s[0] - 'a', s[3] - 'a');
for (auto &s : equations)
if (s[1] == '!' && uf.find(s[0] - 'a') == uf.find(s[3] - 'a'))
return false;
return true;
}
};

diff --git a/Problems/1202.cpp b/Problems/1202.cpp

@@ -0,0 +1,42 @@

class UnionFind {
vector<int> root, rank;
public:
UnionFind(int n) : root(n), rank(n, 1) { iota(root.begin(), root.end(), 0); }
int find(int x) {
if (x == root[x]) return x;
return root[x] = find(root[x]);
}
void join(int x, int y) {
x = find(x), y = find(y);
if (x != y) {
if (rank[x] > rank[y]) swap(x, y);
root[y] = x;
rank[x] += x == y;
}
}
};
class Solution {
public:
string smallestStringWithSwaps(string s, vector<vector<int>> &pairs) {
UnionFind uf(s.size());
vector<vector<char>> vs(s.size());
for (auto &p : pairs) uf.join(p[0], p[1]);
for (int i = 0; i < s.size(); i++) vs[uf.find(i)].push_back(s[i]);
for (auto &s : vs) sort(s.rbegin(), s.rend());
for (int i = 0; i < s.size(); i++) {
int index = uf.find(i);
s[i] = vs[index].back();
vs[index].pop_back();
}
return s;
}
};

diff --git a/Problems/1311.cpp b/Problems/1311.cpp

@@ -0,0 +1,37 @@

class Solution {
public:
vector<string> watchedVideosByFriends(vector<vector<string>> &watchedVideos,
vector<vector<int>> &adj, int id,
int level) {
int n = adj.size();
vector<bool> visited(n, false);
queue<int> q;
q.push(id);
visited[id] = true;
for (int lvl = 0; lvl != level; lvl++) {
for (int k = q.size(); k > 0; k--) {
int id = q.front();
q.pop();
for (int c : adj[id]) {
if (!visited[c]) {
visited[c] = true;
q.push(c);
}
}
}
}
unordered_map<string, int> freq;
vector<pair<int, string>> vec;
vector<string> res;
for (; !q.empty(); q.pop())
for (auto &st : watchedVideos[q.front()]) freq[st]++;
for (auto &[k, v] : freq) vec.push_back({v, k});
sort(vec.begin(), vec.end());
for (auto &[_, title] : vec) res.push_back(title);
return res;
}
};

diff --git a/Problems/1334.cpp b/Problems/1334.cpp

@@ -0,0 +1,57 @@

class Solution {
struct edge {
int index, weight;
edge(int i, int w) : index(i), weight(w) {}
friend bool operator<(const edge &e1, const edge &e2) {
return e1.weight > e2.weight;
}
};
int dijkstra(int n, vector<vector<edge>> &adj, int start, int threshold) {
vector<int> d(n, INT_MAX);
vector<bool> s(n, false);
priority_queue<edge> pq;
for (auto &p : adj[start]) {
d[p.index] = p.weight;
pq.push(p);
}
s[start] = true;
for (int k = 1; k < n; k++) {
while (!pq.empty() && s[pq.top().index]) pq.pop();
if (pq.empty()) break;
auto e = pq.top();
pq.pop();
s[e.index] = true;
for (auto &p : adj[e.index])
if (!s[p.index] && d[e.index] + p.weight < d[p.index]) {
d[p.index] = d[e.index] + p.weight;
pq.push({p.index, d[p.index]});
}
}
int count = 0;
for (int i = 0; i < n; i++) count += d[i] <= threshold;
return count;
}
public:
int findTheCity(int n, vector<vector<int>> &edges, int distanceThreshold) {
vector<vector<edge>> adj(n, vector<edge>());
for (auto &p : edges) {
adj[p[0]].push_back({p[1], p[2]});
adj[p[1]].push_back({p[0], p[2]});
}
int res = -1;
for (int i = 0, mini = INT_MAX; i < n; i++) {
int tmp = dijkstra(n, adj, i, distanceThreshold);
if (tmp <= mini) {
mini = tmp;
res = i;
}
}
return res;
}
};

diff --git a/Problems/1361.cpp b/Problems/1361.cpp

@@ -0,0 +1,51 @@

class UnionFind {
int n;
vector<int> root, rank;
public:
UnionFind(int n) : n(n), root(n), rank(n, 1) {
iota(root.begin(), root.end(), 0);
}
int find(int x) {
while (x != root[x]) x = root[x] = root[root[x]];
return x;
}
void join(int x, int y) {
x = find(x), y = find(y);
if (x != y) {
if (rank[x] > rank[y]) swap(x, y);
root[x] = y;
rank[y] += rank[x];
n--;
}
}
int count() { return n; }
};
class Solution {
bool process(UnionFind &uf, vector<int> &parent, int start, int end) {
if (end == -1) return true;
if (parent[end] != -1) return false;
if (uf.find(start) == uf.find(end)) return false;
uf.join(start, end);
parent[end] = start;
return true;
}
public:
bool validateBinaryTreeNodes(int n, vector<int> &leftChild,
vector<int> &rightChild) {
UnionFind uf(n);
vector<int> parent(n, -1);
for (int i = 0; i < n; i++)
if (!process(uf, parent, i, leftChild[i]) ||
!process(uf, parent, i, rightChild[i]))
return false;
return uf.count() == 1;
}
};

diff --git a/Problems/1514.cpp b/Problems/1514.cpp

@@ -0,0 +1,41 @@

class Solution {
struct edge {
int dest;
double w;
edge(int d, double w) : dest(d), w(w) {}
friend bool operator<(const edge &e1, const edge &e2) {
return e1.w < e2.w;
}
};
public:
double maxProbability(int n, vector<vector<int>> &edges,
vector<double> &succProb, int start, int end) {
vector<vector<edge>> adj(n);
vector<int> visited(n, false);
vector<double> dist(n, 0);
priority_queue<edge> pq;
for (int i = 0; i < succProb.size(); i++) {
adj[edges[i][0]].push_back({edges[i][1], succProb[i]});
adj[edges[i][1]].push_back({edges[i][0], succProb[i]});
}
pq.push({start, dist[start] = 1.0});
for (int k = 0; k < n; k++) {
while (!pq.empty() && visited[pq.top().dest]) pq.pop();
if (pq.empty()) break;
edge c = pq.top();
pq.pop();
if (c.dest == end) return c.w;
visited[c.dest] = true;
for (edge &p : adj[c.dest])
if (!visited[p.dest] && dist[c.dest] * p.w > dist[p.dest]) {
dist[p.dest] = dist[c.dest] * p.w;
pq.push({p.dest, dist[p.dest]});
}
}
return 0;
}
};

diff --git a/Problems/1786.cpp b/Problems/1786.cpp

@@ -0,0 +1,80 @@

class Solution {
const int mod = 1000000007;
struct edge {
int dest, w;
edge(int d, int w) : dest(d), w(w) {}
friend bool operator<(const edge &e1, const edge &e2) {
return e1.w > e2.w;
}
};
vector<int> dijkstra(int n, vector<vector<edge>> &adj, int start) {
vector<int> dist(n + 1, INT_MAX);
priority_queue<edge> pq;
vector<int> visited(n + 1, false);
pq.push({n, dist[n] = 0});
for (int k = 0; k < n; k++) {
while (!pq.empty() && visited[pq.top().dest]) pq.pop();
if (pq.empty()) break;
edge c = pq.top();
pq.pop();
visited[c.dest] = true;
for (edge &p : adj[c.dest])
if (!visited[p.dest] && dist[c.dest] + p.w < dist[p.dest]) {
dist[p.dest] = dist[c.dest] + p.w;
pq.push({p.dest, dist[p.dest]});
}
}
return dist;
}
public:
int countRestrictedPaths(int n, vector<vector<int>> &edges) {
vector<vector<edge>> adj(n + 1);
for (int i = 0; i < edges.size(); i++) {
adj[edges[i][0]].push_back({edges[i][1], edges[i][2]});
adj[edges[i][1]].push_back({edges[i][0], edges[i][2]});
}
vector<int> dist = dijkstra(n, adj, n);
vector<int> dp(n + 1, 0);
vector<int> visited(n + 1, 0);
stack<int> st;
int count = 0;
st.push(1);
while (!st.empty()) {
int root = st.top();
if (root == n) {
st.pop();
count++;
continue;
}
if (root == -1) {
st.pop();
root = st.top();
st.pop();
dp[root] += count;
continue;
}
dp[root] = -count;
visited[root] = true;
st.push(-1);
for (auto [c, w] : adj[root])
if (dist[root] > dist[c]) {
if (visited[c] && dp[c] >= 0)
count = (count + dp[c]) % mod;
else
st.push(c);
}
}
return count;
}
};

diff --git a/Problems/2039.cpp b/Problems/2039.cpp

@@ -0,0 +1,31 @@

class Solution {
public:
int networkBecomesIdle(vector<vector<int>> &edges, vector<int> &patience) {
const int n = patience.size();
vector<vector<int>> adj(n, vector<int>());
for (auto &p : edges) {
adj[p[0]].push_back(p[1]);
adj[p[1]].push_back(p[0]);
}
const int master = 0;
int time = 0;
vector<int> dist(n, 0);
queue<int> q;
q.push(0);
while (!q.empty()) {
int root = q.front();
q.pop();
for (int c : adj[root]) {
if (!dist[c] && c != master) {
dist[c] = dist[root] + 1;
time = max(time, ((2 * dist[c] - 1) / patience[c]) * patience[c] +
2 * dist[c]);
q.push(c);
}
}
}
return time + 1;
}
};

diff --git a/Problems/2101.cpp b/Problems/2101.cpp

@@ -0,0 +1,36 @@

class Solution {
public:
int maximumDetonation(vector<vector<int>> &bombs) {
vector<vector<int>> adj(bombs.size());
for (int i = 0; i < bombs.size(); i++) {
for (int j = i + 1; j < bombs.size(); j++) {
double dist = sqrt(pow(bombs[i][0] - bombs[j][0], 2) +
pow(bombs[i][1] - bombs[j][1], 2));
if (dist <= bombs[i][2]) adj[i].push_back(j);
if (dist <= bombs[j][2]) adj[j].push_back(i);
}
}
int maxi = INT_MIN;
for (int i = 0; i < bombs.size(); i++) {
vector<bool> visited(bombs.size(), false);
int count = 0;
stack<int> st;
st.push(i);
visited[i] = true;
while (!st.empty()) {
int root = st.top();
st.pop();
count++;
for (int c : adj[root])
if (!visited[c]) {
visited[c] = true;
st.push(c);
}
}
maxi = max(maxi, count);
}
return maxi;
}
};

diff --git a/Problems/2115.cpp b/Problems/2115.cpp

@@ -0,0 +1,47 @@

class Solution {
const int SIZE = 101;
public:
vector<string> findAllRecipes(vector<string> &recipes,
vector<vector<string>> &ingredients,
vector<string> &supplies) {
unordered_map<string, int> hash;
unordered_set<string> us(supplies.begin(), supplies.end());
vector<vector<int>> adj(SIZE);
vector<int> count(SIZE);
vector<string> finished;
for (int i = 0; i < recipes.size(); i++) hash.insert({recipes[i], i});
for (int i = 0; i < recipes.size(); i++) {
for (string &s : ingredients[i])
if (!us.count(s)) {
count[i]++;
if (!hash.count(s))
count[i] = INT_MAX;
else
adj[hash[s]].push_back(i);
}
}
queue<int> q;
for (int i = 0; i < recipes.size(); i++) {
if (!count[i]) {
q.push(i);
finished.push_back(recipes[i]);
}
}
while (!q.empty()) {
int root = q.front();
q.pop();
for (int c : adj[root]) {
if (!--count[c]) {
q.push(c);
finished.push_back(recipes[c]);
}
}
}
return finished;
}
};

diff --git a/Problems/2192.cpp b/Problems/2192.cpp

@@ -0,0 +1,24 @@

class Solution {
public:
vector<vector<int>> getAncestors(int n, vector<vector<int>> &edges) {
vector<vector<int>> adj(n, vector<int>());
vector<vector<int>> anc(n, vector<int>());
for (auto &p : edges) adj[p[0]].push_back(p[1]);
for (int i = 0; i < n; i++) {
stack<int> st;
st.push(i);
while (!st.empty()) {
int root = st.top();
st.pop();
for (int c : adj[root]) {
if (!anc[c].empty() && anc[c].back() == i) continue;
anc[c].push_back(i);
st.push(c);
}
}
}
return anc;
}
};

diff --git a/Problems/2374.cpp b/Problems/2374.cpp

@@ -0,0 +1,19 @@

class Solution {
public:
int edgeScore(vector<int> &edges) {
vector<long long> score(edges.size(), 0);
long long maxi = LONG_MIN;
int index = -1;
for (int i = 0; i < edges.size(); i++) {
score[edges[i]] += i;
if (score[edges[i]] > maxi) {
maxi = score[edges[i]];
index = edges[i];
} else if (score[edges[i]] == maxi)
index = min(index, edges[i]);
}
return index;
}
};

diff --git a/Problems/2477.cpp b/Problems/2477.cpp

@@ -0,0 +1,33 @@

class Solution {
public:
long long minimumFuelCost(vector<vector<int>> &roads, int seats) {
int n = roads.size() + 1;
vector<vector<int>> adj(n, vector<int>());
vector<int> count(n, 0);
stack<pair<int, int>> st;
for (auto &p : roads) {
adj[p[0]].push_back(p[1]);
adj[p[1]].push_back(p[0]);
}
long long total = 0;
st.push({0, -1});
while (!st.empty()) {
auto [root, parent] = st.top();
st.pop();
if (parent == -2) {
for (int c : adj[root]) {
count[root] += count[c];
total += ceil(1.0 * count[c] / seats);
}
count[root]++;
continue;
}
st.push({root, -2});
for (int c : adj[root])
if (c != parent) st.push({c, root});
}
return total;
}
};

diff --git a/Problems/2492.cpp b/Problems/2492.cpp

@@ -0,0 +1,36 @@

class UnionFind {
int n;
vector<int> root, rank, res;
public:
UnionFind(int n) : n(n), root(n), rank(n, 1), res(n, INT_MAX) {
iota(root.begin(), root.end(), 0);
}
int find(int x) {
while (x != root[x]) x = root[x] = root[root[x]];
return x;
}
void join(int x, int y, int val) {
x = find(x), y = find(y);
if (x != y) {
if (rank[x] > rank[y]) swap(x, y);
res[y] = min(res[x], res[y]);
root[x] = y;
rank[y] += rank[x];
}
res[y] = min(val, res[y]);
}
int mini(int x) { return res[find(x)]; }
};
class Solution {
public:
int minScore(int n, vector<vector<int>> &roads) {
UnionFind uf(n + 1);
for (auto &r : roads) uf.join(r[0], r[1], r[2]);
return uf.mini(n);
}
};

diff --git a/README.md b/README.md

@@ -12,239 +12,259 @@ if you have any questions.

## Problems
| Number | Difficulty | Solution |
|:------:|:----------:|------------------------------------------------------------------------------------------|
| 0001 | Easy | [Two Sum](Problems/0001.cpp) |
| 0002 | Medium | [Add Two Numbers](Problems/0002.cpp) |
| 0003 | Medium | [Longest Substring Without Repeating Characters](Problems/0003.cpp) |
| 0012 | Medium | [Integer to Roman](Problems/0012.cpp) |
| 0013 | Easy | [Roman to Integer](Problems/0013.cpp) |
| 0014 | Easy | [Longest Common Prefix](Problems/0014.cpp) |
| 0019 | Medium | [Remove Nth Node From the End of List](Problems/0019.cpp) |
| 0020 | Easy | [Valid Parentheses](Problems/0020.cpp) |
| 0021 | Easy | [Merge Two Sorted Lists](Problems/0021.cpp) |
| 0023 | Hard | [Merge k Sorted Lists](Problems/0023.cpp) |
| 0024 | Medium | [Swap Nodes in Pairs](Problems/0024.cpp) |
| 0025 | Hard | [Reverse Nodes in k-Group](Problems/0025.cpp) |
| 0026 | Easy | [Remove Duplicates from Sorted Array](Problems/0026.cpp) |
| 0027 | Easy | [Remove Element](Problems/0027.cpp) |
| 0028 | Medium | [Find the Index of the First Occurrence in a String](Problems/0028.cpp) |
| 0036 | Medium | [Valid Sudoku](Problems/0036.cpp) |
| 0043 | Medium | [Multiply Strings](Problems/0043.cpp) |
| 0049 | Medium | [Group Anagrams](Problems/0049.cpp) |
| 0054 | Medium | [Spiral Matrix](Problems/0054.cpp) |
| 0055 | Medium | [Jump Game](Problems/0055.cpp) |
| 0059 | Medium | [Spiral Matrix II](Problems/0059.cpp) |
| 0061 | Medium | [Rotate List](Problems/0061.cpp) |
| 0066 | Easy | [Plus One](Problems/0066.cpp) |
| 0067 | Easy | [Add Binary](Problems/0067.cpp) |
| 0070 | Easy | [Climbing Stairs](Problems/0070.cpp) |
| 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) |
| 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) |
| 0094 | Easy | [Binary Tree Inorder Traversal](Problems/0094.cpp) |
| 0098 | Medium | [Validate Binary Search Tree](Problems/0098.cpp) |
| 0099 | Medium | [Recover Binary Search Tree](Problems/0099.cpp) |
| 0100 | Easy | [Same Tree](Problems/0100.cpp) |
| 0101 | Easy | [Symmetric Tree](Problems/0101.cpp) |
| 0102 | Medium | [Binary Tree Level Order Traversal](Problems/0102.cpp) |
| 0103 | Medium | [Binary Tree Zigzag Level Order Traversal](Problems/0103.cpp) |
| 0104 | Easy | [Maximum Depth of Binary Tree](Problems/0104.cpp) |
| 0107 | Medium | [Binary Tree Level Order Traversal II](Problems/0107.cpp) |
| 0108 | Easy | [Convert Sorted Array to Binary Search Tree](Problems/0108.cpp) |
| 0109 | Medium | [Convert Sorted List to Binary Search Tree](Problems/0109.cpp) |
| 0110 | Easy | [Balanced Binary Tree](Problems/0110.cpp) |
| 0111 | Easy | [Minimum Depth of Binary Tree](Problems/0111.cpp) |
| 0112 | Easy | [Path Sum](Problems/0112.cpp) |
| 0114 | Medium | [Flatten Binary Tree to Linked List](Problems/0114.cpp) |
| 0116 | Medium | [Populating Next Right Pointers in Each Node](Problems/0116.cpp) |
| 0117 | Medium | [Populating Next Right Pointers in Each Node II](Problems/0117.cpp) |
| 0118 | Easy | [Pascal's Triangle](Problems/0118.cpp) |
| 0119 | Easy | [Pascal's Triangle II](Problems/0119.cpp) |
| 0121 | Easy | [Best Time to Buy and Sell Stock](Problems/0121.cpp) |
| 0122 | Medium | [Best Time to Buy and Sell Stock II](Problems/0122.cpp) |
| 0124 | Hard | [Binary Tree Maximum Path Sum](Problems/0124.cpp) |
| 0125 | Easy | [Valid Palindrome](Problems/0125.cpp) |
| 0133 | Medium | [Clone Graph](Problems/0133.cpp) |
| 0138 | Medium | [Copy List with Random Pointer](Problems/0138.cpp) |
| 0141 | Easy | [Linked List Cycle](Problems/0141.cpp) |
| 0142 | Medium | [Linked List Cycle II](Problems/0142.cpp) |
| 0144 | Medium | [Binary Tree Preorder Traversal](Problems/0144.cpp) |
| 0145 | Easy | [Binary Tree Postorder Traversal](Problems/0145.cpp) |
| 0150 | Medium | [Evaluate Reverse Polish Notation](Problems/0150.cpp) |
| 0151 | Medium | [Reverse Words in a String](Problems/0151.cpp) |
| 0155 | Medium | [Min Stack](Problems/0155.cpp) |
| 0160 | Easy | [Intersection of Two Linked Lists](Problems/0160.cpp) |
| 0167 | Medium | [Two Sum II - Input Array Is Sorted](Problems/0167.cpp) |
| 0173 | Medium | [Binary Search Tree Iterator](Problems/0173.cpp) |
| 0189 | Medium | [Rotate Array](Problems/0189.cpp) |
| 0198 | Medium | [House Robber](Problems/0198.cpp) |
| 0199 | Medium | [Binary Tree Right Side View](Problems/0199.cpp) |
| 0200 | Medium | [Number of Islands](Problems/0200.cpp) |
| 0203 | Easy | [Remove Linked List Elements](Problems/0203.cpp) |
| 0206 | Easy | [Reverse Linked List](Problems/0206.cpp) |
| 0209 | Medium | [Minimum Size Subarray Sum](Problems/0209.cpp) |
| 0217 | Easy | [Contains Duplicate](Problems/0217.cpp) |
| 0222 | Medium | [Count Complete Tree Nodes](Problems/0222.cpp) |
| 0223 | Medium | [Rectangle Area](Problems/0223.cpp) |
| 0226 | Easy | [Invert Binary Tree](Problems/0226.cpp) |
| 0234 | Easy | [Palindrome Linked List](Problems/0234.cpp) |
| 0235 | Medium | [Lowest Common Ancestor of a Binary Search Tree](Problems/0235.cpp) |
| 0236 | Medium | [Lowest Common Ancestor of a Binary Tree](Problems/0236.cpp) |
| 0237 | Medium | [Delete Node in a Linked List](Problems/0237.cpp) |
| 0238 | Medium | [Product of Array Except Self](Problems/0238.cpp) |
| 0242 | Easy | [Valid Anagram](Problems/0242.cpp) |
| 0257 | Easy | [Binary Tree Paths](Problems/0257.cpp) |
| 0263 | Easy | [Ugly Number](Problems/0263.cpp) |
| 0279 | Medium | [Perfect Squares](Problems/0279.cpp) |
| 0283 | Easy | [Move Zeroes](Problems/0283.cpp) |
| 0287 | Medium | [Find the Duplicate Number](Problems/0287.cpp) |
| 0290 | Easy | [Word Pattern](Problems/0290.cpp) |
| 0295 | Hard | [Find Median from Data Stream](Problems/0295.cpp) |
| 0328 | Medium | [Odd Even Linked List](Problems/0328.cpp) |
| 0338 | Easy | [Counting Bits](Problems/0338.cpp) |
| 0344 | Easy | [Reverse String](Problems/0344.cpp) |
| 0345 | Easy | [Reverse Vowels of a String](Problems/0345.cpp) |
| 0347 | Medium | [Top K Frequent Elements](Problems/0347.cpp) |
| 0374 | Easy | [Guess Number Higher or Lower](Problems/0374.cpp) |
| 0383 | Easy | [Ransom Note](Problems/0383.cpp) |
| 0387 | Easy | [First Unique Character in a String](Problems/0387.cpp) |
| 0392 | Easy | [Is Subsequence](Problems/0392.cpp) |
| 0394 | Medium | [Decode String](Problems/0394.cpp) |
| 0404 | Easy | [Sum of Left Leaves](Problems/0404.cpp) |
| 0412 | Easy | [Fizz Buzz](Problems/0412.cpp) |
| 0414 | Easy | [Third Maximum Number](Problems/0414.cpp) |
| 0415 | Easy | [Add Strings](Problems/0415.cpp) |
| 0429 | Medium | [N-ary Tree Level Order Traversal](Problems/0429.cpp) |
| 0430 | Medium | [Flatten a Multilevel Doubly Linked list](Problems/0430.cpp) |
| 0433 | Medium | [Minimum Genetic Mutation](Problems/0433.cpp) |
| 0445 | Medium | [Add Two Numbers II](Problems/0445.cpp) |
| 0448 | Easy | [Find All Numbers Disappeared in an Array](Problems/0448.cpp) |
| 0450 | Medium | [Delete Node in a BST](Problems/0450.cpp) |
| 0485 | Easy | [Max Consecutive Ones](Problems/0485.cpp) |
| 0494 | Medium | [Target Sum](Problems/0494.cpp) |
| 0496 | Medium | [Next Greater Element I](Problems/0496.cpp) |
| 0498 | Medium | [Diagonal Traverse](Problems/0498.cpp) |
| 0501 | Easy | [Find Mode in Binary Search Tree](Problems/0501.cpp) |
| 0503 | Medium | [Next Greater Element II](Problems/0503.cpp) |
| 0509 | Easy | [Fibonacci Number](Problems/0509.cpp) |
| 0530 | Easy | [Minimum Absolute Difference in BST](Problems/0530.cpp) |
| 0538 | Medium | [Convert BST to Greater Tree](Problems/0538.cpp) |
| 0543 | Easy | [Diameter of Binary Tree](Problems/0543.cpp) |
| 0547 | Medium | [Number of Provinces](Problems/0547.cpp) |
| 0556 | Medium | [Next Greater Element III](Problems/0556.cpp) |
| 0557 | Easy | [Reverse Words in a String III](Problems/0557.cpp) |
| 0559 | Easy | [Maximum Depth of N-ary Tree](Problems/0559.cpp) |
| 0561 | Easy | [Array Partition](Problems/0561.cpp) |
| 0563 | Easy | [Binary Tree Tilt](Problems/0563.cpp) |
| 0572 | Easy | [Subtree of Another Tree](Problems/0572.cpp) |
| 0589 | Easy | [N-ary Tree Preorder Traversal](Problems/0589.cpp) |
| 0590 | Easy | [N-ary Tree Postorder Traversal](Problems/0590.cpp) |
| 0606 | Easy | [Construct String from Binary Tree ](Problems/0606.cpp) |
| 0617 | Easy | [Merge Two Binary Trees](Problems/0617.cpp) |
| 0637 | Easy | [Average of Levels in Binary Tree](Problems/0637.cpp) |
| 0653 | Easy | [Two Sum IV - Input is a BST](Problems/0653.cpp) |
| 0654 | Medium | [Maximum Binary Tree](Problems/0654.cpp) |
| 0669 | Medium | [Trim a Binary Search Tree](Problems/0669.cpp) |
| 0671 | Easy | [Second Minimum Node In a Binary Tree](Problems/0671.cpp) |
| 0684 | Medium | [Redundant Connection](Problems/0684.cpp) |
| 0700 | Easy | [Search in a Binary Search Tree](Problems/0700.cpp) |
| 0701 | Medium | [Insert into a Binary Search Tree](Problems/0701.cpp) |
| 0707 | Medium | [Design Linked List](Problems/0707.cpp) |
| 0724 | Easy | [Find Pivot Index](Problems/0724.cpp) |
| 0733 | Easy | [Flood Fill](Problems/0733.cpp) |
| 0739 | Medium | [Daily Temperatures](Problems/0739.cpp) |
| 0746 | Easy | [Min Cost Climbing Stairs](Problems/0746.cpp) |
| 0747 | Easy | [Largest Number At Least Twice of Others](Problems/0747.cpp) |
| 0752 | Medium | [Open the Lock](Problems/0752.cpp) |
| 0783 | Easy | [Minimum Distance Between BST Nodes](Problems/0783.cpp) |
| 0797 | Medium | [All Paths From Source to Target](Problems/0797.cpp) |
| 0802 | Medium | [Find Eventual Safe States](Problems/0802.cpp) |
| 0830 | Medium | [Kth Smallest Element in a BST](Problems/0230.cpp) |
| 0841 | Medium | [Keys and Rooms](Problems/0841.cpp) |
| 0844 | Easy | [Backspace String Compare](Problems/0844.cpp) |
| 0872 | Easy | [Leaf-Similar Trees](Problems/0872.cpp) |
| 0876 | Easy | [Middle of the Linked List](Problems/0876.cpp) |
| 0886 | Medium | [Possible Bipartition](Problems/0886.cpp) |
| 0897 | Easy | [Increasing Order Search Tree](Problems/0897.cpp) |
| 0901 | Medium | [Online Stock Span](Problems/0901.cpp) |
| 0905 | Easy | [Sort Array By Parity](Problems/0905.cpp) |
| 0931 | Medium | [Minimum Falling Path Sum](Problems/0931.cpp) |
| 0933 | Easy | [Number of Recent Calls](Problems/0933.cpp) |
| 0938 | Easy | [Range Sum of BST](Problems/0938.cpp) |
| 0941 | Easy | [Valid Mountain Array](Problems/0941.cpp) |
| 0947 | Medium | [Most Stones Removed with Same Row or Column](Problems/0947.cpp) |
| 0950 | Medium | [Reveal Cards In Increasing Order](Problems/0950.cpp) |
| 0959 | Medium | [Regions Cut By Slashes](Problems/0959.cpp) |
| 0965 | Easy | [Univalued Binary Tree](Problems/0965.cpp) |
| 0977 | Easy | [Squares of a Sorted Array](Problems/0977.cpp) |
| 0980 | Hard | [Unique Paths III](Problems/0980.cpp) |
| 0989 | Easy | [Add to Array-Form of Integer](Problems/0989.cpp) |
| 0993 | Easy | [Cousins in Binary Tree](Problems/0993.cpp) |
| 0997 | Easy | [Find the Town Judge](Problems/0997.cpp) |
| 1008 | Medium | [Construct Binary Search Tree from Preorder Traversal](Problems/1008.cpp) |
| 1019 | Medium | [Next Greater Node In Linked List](Problems/1019.cpp) |
| 1022 | Easy | [Sum of Root To Leaf Binary Numbers](Problems/1022.cpp) |
| 1026 | Medium | [Maximum Difference Between Node and Ancestor](Problems/1026.cpp) |
| 1038 | Medium | [Binary Search Tree to Greater Sum Tree](Problems/1038.cpp) |
| 1047 | Easy | [Remove All Adjacent Duplicates In String](Problems/1047.cpp) |
| 1051 | Easy | [Height Checker](Problems/1051.cpp) |
| 1089 | Easy | [Duplicate Zeros](Problems/1089.cpp) |
| 1095 | Easy | [Find Numbers with Even Number of Digits](Problems/1095.cpp) |
| 1099 | Easy | [Replace Elements with Greatest Element on Right Side](Problems/1099.cpp) |
| 1137 | Easy | [N-th Tribonacci Number](Problems/1137.cpp) |
| 1209 | Medium | [Remove All Adjacent Duplicates in String II](Problems/1209.cpp) |
| 1290 | Easy | [Convert Binary Number in a Linked List to Integer](Problems/1290.cpp) |
| 1302 | Medium | [Deepest Leaves Sum](Problems/1302.cpp) |
| 1305 | Medium | [All Elements in Two Binary Search Trees](Problems/1305.cpp) |
| 1315 | Medium | [Sum of Nodes with Even-Valued Grandparent](Problems/1315.cpp) |
| 1319 | Medium | [Number of Operations to Make Network Connected](Problems/1319.cpp) |
| 1323 | Easy | [Maximum 69 Number](Problems/1323.cpp) |
| 1337 | Easy | [The K Weakest Rows in a Matrix](Problems/1337.cpp) |
| 1339 | Medium | [Maximum Product of Splitted Binary Tree](Problems/1339.cpp) |
| 1342 | Easy | [Number of Steps to Reduce a Number to Zero](Problems/1342.cpp) |
| 1346 | Easy | [Check if N and Its Double Exist](Problems/1346.cpp) |
| 1367 | Medium | [Linked List in Binary Tree ](Problems/1367.cpp) |
| 1373 | Hard | [Maximum Sum BST in Binary Tree](Problems/1373.cpp) |
| 1379 | Easy | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree ](Problems/1379.cpp) |
| 1382 | Medium | [Balance a Binary Search Tree](Problems/1382.cpp) |
| 1466 | Medium | [Reorder Routes to Make All Paths Lead to the City Zero](Problems/1466.cpp) |
| 1472 | Medium | [Design Browser History ](Problems/1472.cpp) |
| 1480 | Easy | [Running Sum of 1d Array](Problems/1480.cpp) |
| 1544 | Easy | [Make The String Great](Problems/1544.cpp) |
| 1557 | Medium | [Minimum Number of Vertices to Reach All Nodes](Problems/1557.cpp) |
| 1584 | Medium | [Min Cost to Connect All Points](Problems/1584.cpp) |
| 1609 | Medium | [Even Odd Tree](Problems/1609.cpp) |
| 1615 | Medium | [Maximal Network Rank](Problems/1615.cpp) |
| 1646 | Easy | [Get Maximum in Generated Array](Problems/1646.cpp) |
| 1669 | Medium | [Merge In Between Linked Lists](Problems/1669.cpp) |
| 1672 | Easy | [Richest Customer Wealth](Problems/1672.cpp) |
| 1696 | Medium | [Jump Game VI](Problems/1696.cpp) |
| 1700 | Easy | [Number of Students Unable to Eat Lunch](Problems/1700.cpp) |
| 1704 | Easy | [Determine if String Halves Are Alike](Problems/1704.cpp) |
| 1706 | Medium | [Where Will the Ball Fall](Problems/1706.cpp) |
| 1791 | Easy | [Find Center of Star Graph](Problems/1791.cpp) |
| 1823 | Medium | [Find the Winner of the Circular Game](Problems/1823.cpp) |
| 1834 | Medium | [Single-Threaded CPU](Problems/1834.cpp) |
| 1926 | Medium | [Nearest Exit from Entrance in Maze](Problems/1926.cpp) |
| 1962 | Medium | [Remove Stones to Minimize the Total](Problems/1962.cpp) |
| 1971 | Easy | [Find if Path Exists in Graph](Problems/1971.cpp) |
| 2073 | Easy | [Time Needed to Buy Tickets](Problems/2073.cpp) |
| 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) |
| 2130 | Medium | [Maximum Twin Sum of a Linked List](Problems/2130.cpp) |
| 2131 | Medium | [Longest Palindrome by Concatenating Two Letter Words](Problems/2131.cpp) |
| 2181 | Medium | [Merge Nodes in Between Zeros](Problems/2181.cpp) |
| 2235 | Easy | [Add Two Integers](Problems/2235.cpp) |
| 2236 | Easy | [Root Equals Sum of Children](Problems/2236.cpp) |
| 2265 | Medium | [Count Nodes Equal to Average of Subtree](Problems/2265.cpp) |
| 2279 | Medium | [Maximum Bags With Full Capacity of Rocks](Problems/2279.cpp) |
| 2285 | Medium | [Maximum Total Importance of Roads](Problems/2285.cpp) |
| 2326 | Medium | [Spiral Matrix IV](Problems/2326.cpp) |
| 2331 | Easy | [Evaluate Boolean Binary Tree](Problems/2331.cpp) |
| 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) |
| 2390 | Medium | [Removing Stars From a String](Problems/2390.cpp) |
| 2465 | Easy | [Number of Distinct Averages](Problems/2465.cpp) |
| 2466 | Medium | [Count Ways To Build Good Strings](Problems/2466.cpp) |
| 2467 | Medium | [Most Profitable Path in a Tree](Problems/2467.cpp) |
| Number | Difficulty | Solution |
|:------:|:----------:|--------------------------------------------------------------------------------------------------|
| 0001 | Easy | [Two Sum](Problems/0001.cpp) |
| 0002 | Medium | [Add Two Numbers](Problems/0002.cpp) |
| 0003 | Medium | [Longest Substring Without Repeating Characters](Problems/0003.cpp) |
| 0012 | Medium | [Integer to Roman](Problems/0012.cpp) |
| 0013 | Easy | [Roman to Integer](Problems/0013.cpp) |
| 0014 | Easy | [Longest Common Prefix](Problems/0014.cpp) |
| 0019 | Medium | [Remove Nth Node From the End of List](Problems/0019.cpp) |
| 0020 | Easy | [Valid Parentheses](Problems/0020.cpp) |
| 0021 | Easy | [Merge Two Sorted Lists](Problems/0021.cpp) |
| 0023 | Hard | [Merge k Sorted Lists](Problems/0023.cpp) |
| 0024 | Medium | [Swap Nodes in Pairs](Problems/0024.cpp) |
| 0025 | Hard | [Reverse Nodes in k-Group](Problems/0025.cpp) |
| 0026 | Easy | [Remove Duplicates from Sorted Array](Problems/0026.cpp) |
| 0027 | Easy | [Remove Element](Problems/0027.cpp) |
| 0028 | Medium | [Find the Index of the First Occurrence in a String](Problems/0028.cpp) |
| 0036 | Medium | [Valid Sudoku](Problems/0036.cpp) |
| 0043 | Medium | [Multiply Strings](Problems/0043.cpp) |
| 0049 | Medium | [Group Anagrams](Problems/0049.cpp) |
| 0054 | Medium | [Spiral Matrix](Problems/0054.cpp) |
| 0055 | Medium | [Jump Game](Problems/0055.cpp) |
| 0059 | Medium | [Spiral Matrix II](Problems/0059.cpp) |
| 0061 | Medium | [Rotate List](Problems/0061.cpp) |
| 0066 | Easy | [Plus One](Problems/0066.cpp) |
| 0067 | Easy | [Add Binary](Problems/0067.cpp) |
| 0070 | Easy | [Climbing Stairs](Problems/0070.cpp) |
| 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) |
| 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) |
| 0094 | Easy | [Binary Tree Inorder Traversal](Problems/0094.cpp) |
| 0098 | Medium | [Validate Binary Search Tree](Problems/0098.cpp) |
| 0099 | Medium | [Recover Binary Search Tree](Problems/0099.cpp) |
| 0100 | Easy | [Same Tree](Problems/0100.cpp) |
| 0101 | Easy | [Symmetric Tree](Problems/0101.cpp) |
| 0102 | Medium | [Binary Tree Level Order Traversal](Problems/0102.cpp) |
| 0103 | Medium | [Binary Tree Zigzag Level Order Traversal](Problems/0103.cpp) |
| 0104 | Easy | [Maximum Depth of Binary Tree](Problems/0104.cpp) |
| 0107 | Medium | [Binary Tree Level Order Traversal II](Problems/0107.cpp) |
| 0108 | Easy | [Convert Sorted Array to Binary Search Tree](Problems/0108.cpp) |
| 0109 | Medium | [Convert Sorted List to Binary Search Tree](Problems/0109.cpp) |
| 0110 | Easy | [Balanced Binary Tree](Problems/0110.cpp) |
| 0111 | Easy | [Minimum Depth of Binary Tree](Problems/0111.cpp) |
| 0112 | Easy | [Path Sum](Problems/0112.cpp) |
| 0114 | Medium | [Flatten Binary Tree to Linked List](Problems/0114.cpp) |
| 0116 | Medium | [Populating Next Right Pointers in Each Node](Problems/0116.cpp) |
| 0117 | Medium | [Populating Next Right Pointers in Each Node II](Problems/0117.cpp) |
| 0118 | Easy | [Pascal's Triangle](Problems/0118.cpp) |
| 0119 | Easy | [Pascal's Triangle II](Problems/0119.cpp) |
| 0121 | Easy | [Best Time to Buy and Sell Stock](Problems/0121.cpp) |
| 0122 | Medium | [Best Time to Buy and Sell Stock II](Problems/0122.cpp) |
| 0124 | Hard | [Binary Tree Maximum Path Sum](Problems/0124.cpp) |
| 0125 | Easy | [Valid Palindrome](Problems/0125.cpp) |
| 0133 | Medium | [Clone Graph](Problems/0133.cpp) |
| 0138 | Medium | [Copy List with Random Pointer](Problems/0138.cpp) |
| 0141 | Easy | [Linked List Cycle](Problems/0141.cpp) |
| 0142 | Medium | [Linked List Cycle II](Problems/0142.cpp) |
| 0144 | Medium | [Binary Tree Preorder Traversal](Problems/0144.cpp) |
| 0145 | Easy | [Binary Tree Postorder Traversal](Problems/0145.cpp) |
| 0150 | Medium | [Evaluate Reverse Polish Notation](Problems/0150.cpp) |
| 0151 | Medium | [Reverse Words in a String](Problems/0151.cpp) |
| 0155 | Medium | [Min Stack](Problems/0155.cpp) |
| 0160 | Easy | [Intersection of Two Linked Lists](Problems/0160.cpp) |
| 0167 | Medium | [Two Sum II - Input Array Is Sorted](Problems/0167.cpp) |
| 0173 | Medium | [Binary Search Tree Iterator](Problems/0173.cpp) |
| 0189 | Medium | [Rotate Array](Problems/0189.cpp) |
| 0198 | Medium | [House Robber](Problems/0198.cpp) |
| 0199 | Medium | [Binary Tree Right Side View](Problems/0199.cpp) |
| 0200 | Medium | [Number of Islands](Problems/0200.cpp) |
| 0203 | Easy | [Remove Linked List Elements](Problems/0203.cpp) |
| 0206 | Easy | [Reverse Linked List](Problems/0206.cpp) |
| 0207 | Medium | [Course Schedule](Problems/0207.cpp) |
| 0209 | Medium | [Minimum Size Subarray Sum](Problems/0209.cpp) |
| 0210 | Medium | [Course Schedule II](Problems/0210.cpp) |
| 0217 | Easy | [Contains Duplicate](Problems/0217.cpp) |
| 0222 | Medium | [Count Complete Tree Nodes](Problems/0222.cpp) |
| 0223 | Medium | [Rectangle Area](Problems/0223.cpp) |
| 0226 | Easy | [Invert Binary Tree](Problems/0226.cpp) |
| 0234 | Easy | [Palindrome Linked List](Problems/0234.cpp) |
| 0235 | Medium | [Lowest Common Ancestor of a Binary Search Tree](Problems/0235.cpp) |
| 0236 | Medium | [Lowest Common Ancestor of a Binary Tree](Problems/0236.cpp) |
| 0237 | Medium | [Delete Node in a Linked List](Problems/0237.cpp) |
| 0238 | Medium | [Product of Array Except Self](Problems/0238.cpp) |
| 0242 | Easy | [Valid Anagram](Problems/0242.cpp) |
| 0257 | Easy | [Binary Tree Paths](Problems/0257.cpp) |
| 0263 | Easy | [Ugly Number](Problems/0263.cpp) |
| 0279 | Medium | [Perfect Squares](Problems/0279.cpp) |
| 0283 | Easy | [Move Zeroes](Problems/0283.cpp) |
| 0287 | Medium | [Find the Duplicate Number](Problems/0287.cpp) |
| 0290 | Easy | [Word Pattern](Problems/0290.cpp) |
| 0295 | Hard | [Find Median from Data Stream](Problems/0295.cpp) |
| 0328 | Medium | [Odd Even Linked List](Problems/0328.cpp) |
| 0338 | Easy | [Counting Bits](Problems/0338.cpp) |
| 0344 | Easy | [Reverse String](Problems/0344.cpp) |
| 0345 | Easy | [Reverse Vowels of a String](Problems/0345.cpp) |
| 0347 | Medium | [Top K Frequent Elements](Problems/0347.cpp) |
| 0374 | Easy | [Guess Number Higher or Lower](Problems/0374.cpp) |
| 0383 | Easy | [Ransom Note](Problems/0383.cpp) |
| 0387 | Easy | [First Unique Character in a String](Problems/0387.cpp) |
| 0392 | Easy | [Is Subsequence](Problems/0392.cpp) |
| 0394 | Medium | [Decode String](Problems/0394.cpp) |
| 0399 | Medium | [Evaluate Division](Problems/0399.cpp) |
| 0404 | Easy | [Sum of Left Leaves](Problems/0404.cpp) |
| 0412 | Easy | [Fizz Buzz](Problems/0412.cpp) |
| 0414 | Easy | [Third Maximum Number](Problems/0414.cpp) |
| 0415 | Easy | [Add Strings](Problems/0415.cpp) |
| 0429 | Medium | [N-ary Tree Level Order Traversal](Problems/0429.cpp) |
| 0430 | Medium | [Flatten a Multilevel Doubly Linked list](Problems/0430.cpp) |
| 0433 | Medium | [Minimum Genetic Mutation](Problems/0433.cpp) |
| 0445 | Medium | [Add Two Numbers II](Problems/0445.cpp) |
| 0448 | Easy | [Find All Numbers Disappeared in an Array](Problems/0448.cpp) |
| 0450 | Medium | [Delete Node in a BST](Problems/0450.cpp) |
| 0485 | Easy | [Max Consecutive Ones](Problems/0485.cpp) |
| 0494 | Medium | [Target Sum](Problems/0494.cpp) |
| 0496 | Medium | [Next Greater Element I](Problems/0496.cpp) |
| 0498 | Medium | [Diagonal Traverse](Problems/0498.cpp) |
| 0501 | Easy | [Find Mode in Binary Search Tree](Problems/0501.cpp) |
| 0503 | Medium | [Next Greater Element II](Problems/0503.cpp) |
| 0509 | Easy | [Fibonacci Number](Problems/0509.cpp) |
| 0520 | Easy | [Detect Capital](Problems/0520.cpp) |
| 0530 | Easy | [Minimum Absolute Difference in BST](Problems/0530.cpp) |
| 0538 | Medium | [Convert BST to Greater Tree](Problems/0538.cpp) |
| 0543 | Easy | [Diameter of Binary Tree](Problems/0543.cpp) |
| 0547 | Medium | [Number of Provinces](Problems/0547.cpp) |
| 0556 | Medium | [Next Greater Element III](Problems/0556.cpp) |
| 0557 | Easy | [Reverse Words in a String III](Problems/0557.cpp) |
| 0559 | Easy | [Maximum Depth of N-ary Tree](Problems/0559.cpp) |
| 0561 | Easy | [Array Partition](Problems/0561.cpp) |
| 0563 | Easy | [Binary Tree Tilt](Problems/0563.cpp) |
| 0572 | Easy | [Subtree of Another Tree](Problems/0572.cpp) |
| 0589 | Easy | [N-ary Tree Preorder Traversal](Problems/0589.cpp) |
| 0590 | Easy | [N-ary Tree Postorder Traversal](Problems/0590.cpp) |
| 0606 | Easy | [Construct String from Binary Tree ](Problems/0606.cpp) |
| 0617 | Easy | [Merge Two Binary Trees](Problems/0617.cpp) |
| 0637 | Easy | [Average of Levels in Binary Tree](Problems/0637.cpp) |
| 0653 | Easy | [Two Sum IV - Input is a BST](Problems/0653.cpp) |
| 0654 | Medium | [Maximum Binary Tree](Problems/0654.cpp) |
| 0669 | Medium | [Trim a Binary Search Tree](Problems/0669.cpp) |
| 0671 | Easy | [Second Minimum Node In a Binary Tree](Problems/0671.cpp) |
| 0684 | Medium | [Redundant Connection](Problems/0684.cpp) |
| 0700 | Easy | [Search in a Binary Search Tree](Problems/0700.cpp) |
| 0701 | Medium | [Insert into a Binary Search Tree](Problems/0701.cpp) |
| 0707 | Medium | [Design Linked List](Problems/0707.cpp) |
| 0724 | Easy | [Find Pivot Index](Problems/0724.cpp) |
| 0733 | Easy | [Flood Fill](Problems/0733.cpp) |
| 0739 | Medium | [Daily Temperatures](Problems/0739.cpp) |
| 0743 | Medium | [Network Delay Time](Problems/0743.cpp) |
| 0746 | Easy | [Min Cost Climbing Stairs](Problems/0746.cpp) |
| 0747 | Easy | [Largest Number At Least Twice of Others](Problems/0747.cpp) |
| 0752 | Medium | [Open the Lock](Problems/0752.cpp) |
| 0783 | Easy | [Minimum Distance Between BST Nodes](Problems/0783.cpp) |
| 0785 | Medium | [Is Graph Bipartite?](Problems/0785.cpp) |
| 0797 | Medium | [All Paths From Source to Target](Problems/0797.cpp) |
| 0802 | Medium | [Find Eventual Safe States](Problems/0802.cpp) |
| 0830 | Medium | [Kth Smallest Element in a BST](Problems/0230.cpp) |
| 0841 | Medium | [Keys and Rooms](Problems/0841.cpp) |
| 0844 | Easy | [Backspace String Compare](Problems/0844.cpp) |
| 0872 | Easy | [Leaf-Similar Trees](Problems/0872.cpp) |
| 0876 | Easy | [Middle of the Linked List](Problems/0876.cpp) |
| 0886 | Medium | [Possible Bipartition](Problems/0886.cpp) |
| 0897 | Easy | [Increasing Order Search Tree](Problems/0897.cpp) |
| 0901 | Medium | [Online Stock Span](Problems/0901.cpp) |
| 0905 | Easy | [Sort Array By Parity](Problems/0905.cpp) |
| 0931 | Medium | [Minimum Falling Path Sum](Problems/0931.cpp) |
| 0933 | Easy | [Number of Recent Calls](Problems/0933.cpp) |
| 0938 | Easy | [Range Sum of BST](Problems/0938.cpp) |
| 0941 | Easy | [Valid Mountain Array](Problems/0941.cpp) |
| 0947 | Medium | [Most Stones Removed with Same Row or Column](Problems/0947.cpp) |
| 0950 | Medium | [Reveal Cards In Increasing Order](Problems/0950.cpp) |
| 0959 | Medium | [Regions Cut By Slashes](Problems/0959.cpp) |
| 0965 | Easy | [Univalued Binary Tree](Problems/0965.cpp) |
| 0977 | Easy | [Squares of a Sorted Array](Problems/0977.cpp) |
| 0980 | Hard | [Unique Paths III](Problems/0980.cpp) |
| 0989 | Easy | [Add to Array-Form of Integer](Problems/0989.cpp) |
| 0990 | Medium | [Satisfiability of Equality Equations](Problems/0990.cpp) |
| 0993 | Easy | [Cousins in Binary Tree](Problems/0993.cpp) |
| 0997 | Easy | [Find the Town Judge](Problems/0997.cpp) |
| 1008 | Medium | [Construct Binary Search Tree from Preorder Traversal](Problems/1008.cpp) |
| 1019 | Medium | [Next Greater Node In Linked List](Problems/1019.cpp) |
| 1022 | Easy | [Sum of Root To Leaf Binary Numbers](Problems/1022.cpp) |
| 1026 | Medium | [Maximum Difference Between Node and Ancestor](Problems/1026.cpp) |
| 1038 | Medium | [Binary Search Tree to Greater Sum Tree](Problems/1038.cpp) |
| 1047 | Easy | [Remove All Adjacent Duplicates In String](Problems/1047.cpp) |
| 1051 | Easy | [Height Checker](Problems/1051.cpp) |
| 1089 | Easy | [Duplicate Zeros](Problems/1089.cpp) |
| 1095 | Easy | [Find Numbers with Even Number of Digits](Problems/1095.cpp) |
| 1099 | Easy | [Replace Elements with Greatest Element on Right Side](Problems/1099.cpp) |
| 1137 | Easy | [N-th Tribonacci Number](Problems/1137.cpp) |
| 1202 | Medium | [Smallest String With Swaps](Problems/1202.cpp) |
| 1209 | Medium | [Remove All Adjacent Duplicates in String II](Problems/1209.cpp) |
| 1290 | Easy | [Convert Binary Number in a Linked List to Integer](Problems/1290.cpp) |
| 1302 | Medium | [Deepest Leaves Sum](Problems/1302.cpp) |
| 1305 | Medium | [All Elements in Two Binary Search Trees](Problems/1305.cpp) |
| 1311 | Medium | [Get Watched Videos by Your Friends](Problems/1311.cpp) |
| 1315 | Medium | [Sum of Nodes with Even-Valued Grandparent](Problems/1315.cpp) |
| 1319 | Medium | [Number of Operations to Make Network Connected](Problems/1319.cpp) |
| 1323 | Easy | [Maximum 69 Number](Problems/1323.cpp) |
| 1334 | Medium | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](Problems/1334.cpp) |
| 1337 | Easy | [The K Weakest Rows in a Matrix](Problems/1337.cpp) |
| 1339 | Medium | [Maximum Product of Splitted Binary Tree](Problems/1339.cpp) |
| 1342 | Easy | [Number of Steps to Reduce a Number to Zero](Problems/1342.cpp) |
| 1346 | Easy | [Check if N and Its Double Exist](Problems/1346.cpp) |
| 1361 | Medium | [Validate Binary Tree Nodes](Problems/1361.cpp) |
| 1367 | Medium | [Linked List in Binary Tree ](Problems/1367.cpp) |
| 1373 | Hard | [Maximum Sum BST in Binary Tree](Problems/1373.cpp) |
| 1379 | Easy | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](Problems/1379.cpp) |
| 1382 | Medium | [Balance a Binary Search Tree](Problems/1382.cpp) |
| 1466 | Medium | [Reorder Routes to Make All Paths Lead to the City Zero](Problems/1466.cpp) |
| 1472 | Medium | [Design Browser History ](Problems/1472.cpp) |
| 1480 | Easy | [Running Sum of 1d Array](Problems/1480.cpp) |
| 1514 | Medium | [Path with Maximum Probability](Problems/1514.cpp) |
| 1544 | Easy | [Make The String Great](Problems/1544.cpp) |
| 1557 | Medium | [Minimum Number of Vertices to Reach All Nodes](Problems/1557.cpp) |
| 1584 | Medium | [Min Cost to Connect All Points](Problems/1584.cpp) |
| 1609 | Medium | [Even Odd Tree](Problems/1609.cpp) |
| 1615 | Medium | [Maximal Network Rank](Problems/1615.cpp) |
| 1646 | Easy | [Get Maximum in Generated Array](Problems/1646.cpp) |
| 1669 | Medium | [Merge In Between Linked Lists](Problems/1669.cpp) |
| 1672 | Easy | [Richest Customer Wealth](Problems/1672.cpp) |
| 1696 | Medium | [Jump Game VI](Problems/1696.cpp) |
| 1700 | Easy | [Number of Students Unable to Eat Lunch](Problems/1700.cpp) |
| 1704 | Easy | [Determine if String Halves Are Alike](Problems/1704.cpp) |
| 1706 | Medium | [Where Will the Ball Fall](Problems/1706.cpp) |
| 1786 | Medium | [Number of Restricted Paths From First to Last Node](Problems/1786.cpp) |
| 1791 | Easy | [Find Center of Star Graph](Problems/1791.cpp) |
| 1823 | Medium | [Find the Winner of the Circular Game](Problems/1823.cpp) |
| 1834 | Medium | [Single-Threaded CPU](Problems/1834.cpp) |
| 1926 | Medium | [Nearest Exit from Entrance in Maze](Problems/1926.cpp) |
| 1962 | Medium | [Remove Stones to Minimize the Total](Problems/1962.cpp) |
| 1971 | Easy | [Find if Path Exists in Graph](Problems/1971.cpp) |
| 2039 | Medium | [The Time When the Network Becomes Idle](Problems/2039.cpp) |
| 2073 | Easy | [Time Needed to Buy Tickets](Problems/2073.cpp) |
| 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) |
| 2101 | Medium | [Detonate the Maximum Bombs](Problems/2101.cpp) |
| 2115 | Medium | [Find All Possible Recipes from Given Supplies](Problems/2115.cpp) |
| 2130 | Medium | [Maximum Twin Sum of a Linked List](Problems/2130.cpp) |
| 2131 | Medium | [Longest Palindrome by Concatenating Two Letter Words](Problems/2131.cpp) |
| 2181 | Medium | [Merge Nodes in Between Zeros](Problems/2181.cpp) |
| 2192 | Medium | [All Ancestors of a Node in a Directed Acyclic Graph](Problems/2192.cpp) |
| 2235 | Easy | [Add Two Integers](Problems/2235.cpp) |
| 2236 | Easy | [Root Equals Sum of Children](Problems/2236.cpp) |
| 2265 | Medium | [Count Nodes Equal to Average of Subtree](Problems/2265.cpp) |
| 2279 | Medium | [Maximum Bags With Full Capacity of Rocks](Problems/2279.cpp) |
| 2285 | Medium | [Maximum Total Importance of Roads](Problems/2285.cpp) |
| 2326 | Medium | [Spiral Matrix IV](Problems/2326.cpp) |
| 2331 | Easy | [Evaluate Boolean Binary Tree](Problems/2331.cpp) |
| 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) |
| 2374 | Medium | [Node With Highest Edge Score](Problems/2374.cpp) |
| 2390 | Medium | [Removing Stars From a String](Problems/2390.cpp) |
| 2465 | Easy | [Number of Distinct Averages](Problems/2465.cpp) |
| 2466 | Medium | [Count Ways To Build Good Strings](Problems/2466.cpp) |
| 2467 | Medium | [Most Profitable Path in a Tree](Problems/2467.cpp) |
| 2477 | Medium | [Minimum Fuel Cost to Report to the Capital](Problems/2477.cpp) |
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
## DNF