Dataset Viewer
Auto-converted to Parquet Duplicate
question_id
int64
1
3.58k
name
stringlengths
3
77
content
stringlengths
516
21.8k
acRate
float64
9.95
93
difficulty
stringclasses
3 values
topics
sequencelengths
1
10
runtimeDistribution
stringlengths
49
2.26k
memoryDistribution
stringlengths
88
2.23k
rt_list
listlengths
0
152
rt_solution_count
int64
0
152
mm_list
listlengths
0
153
mm_solution_count
int64
0
153
1,058
lexicographically-smallest-equivalent-string
<p>You are given two strings of the same length <code>s1</code> and <code>s2</code> and a string <code>baseStr</code>.</p> <p>We say <code>s1[i]</code> and <code>s2[i]</code> are equivalent characters.</p> <ul> <li>For example, if <code>s1 = &quot;abc&quot;</code> and <code>s2 = &quot;cde&quot;</code>, then we have <code>&#39;a&#39; == &#39;c&#39;</code>, <code>&#39;b&#39; == &#39;d&#39;</code>, and <code>&#39;c&#39; == &#39;e&#39;</code>.</li> </ul> <p>Equivalent characters follow the usual rules of any equivalence relation:</p> <ul> <li><strong>Reflexivity:</strong> <code>&#39;a&#39; == &#39;a&#39;</code>.</li> <li><strong>Symmetry:</strong> <code>&#39;a&#39; == &#39;b&#39;</code> implies <code>&#39;b&#39; == &#39;a&#39;</code>.</li> <li><strong>Transitivity:</strong> <code>&#39;a&#39; == &#39;b&#39;</code> and <code>&#39;b&#39; == &#39;c&#39;</code> implies <code>&#39;a&#39; == &#39;c&#39;</code>.</li> </ul> <p>For example, given the equivalency information from <code>s1 = &quot;abc&quot;</code> and <code>s2 = &quot;cde&quot;</code>, <code>&quot;acd&quot;</code> and <code>&quot;aab&quot;</code> are equivalent strings of <code>baseStr = &quot;eed&quot;</code>, and <code>&quot;aab&quot;</code> is the lexicographically smallest equivalent string of <code>baseStr</code>.</p> <p>Return <em>the lexicographically smallest equivalent string of </em><code>baseStr</code><em> by using the equivalency information from </em><code>s1</code><em> and </em><code>s2</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s1 = &quot;parker&quot;, s2 = &quot;morris&quot;, baseStr = &quot;parser&quot; <strong>Output:</strong> &quot;makkek&quot; <strong>Explanation:</strong> Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i]. The characters in each group are equivalent and sorted in lexicographical order. So the answer is &quot;makkek&quot;. </pre> <p><strong class="example">Example 2:</strong></p> <pre> <strong>Input:</strong> s1 = &quot;hello&quot;, s2 = &quot;world&quot;, baseStr = &quot;hold&quot; <strong>Output:</strong> &quot;hdld&quot; <strong>Explanation: </strong>Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r]. So only the second letter &#39;o&#39; in baseStr is changed to &#39;d&#39;, the answer is &quot;hdld&quot;. </pre> <p><strong class="example">Example 3:</strong></p> <pre> <strong>Input:</strong> s1 = &quot;leetcode&quot;, s2 = &quot;programs&quot;, baseStr = &quot;sourcecode&quot; <strong>Output:</strong> &quot;aauaaaaada&quot; <strong>Explanation:</strong> We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except &#39;u&#39; and &#39;d&#39; are transformed to &#39;a&#39;, the answer is &quot;aauaaaaada&quot;. </pre> <p>&nbsp;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 &lt;= s1.length, s2.length, baseStr &lt;= 1000</code></li> <li><code>s1.length == s2.length</code></li> <li><code>s1</code>, <code>s2</code>, and <code>baseStr</code> consist of lowercase English letters.</li> </ul>
76.709554
Medium
[ "string", "union-find" ]
{"lang": "cpp", "distribution": [["0", 26.3784], ["1", 0.1081], ["2", 6.5946], ["3", 3.4595], ["4", 14.3784], ["5", 14.0541], ["6", 3.3514], ["7", 2.4865], ["8", 2.9189], ["9", 0.5405], ["10", 0.5405], ["11", 1.1892], ["12", 0.3243], ["13", 0.2162], ["14", 0.973], ["15", 1.6216], ["16", 0.973], ["17", 1.1892], ["18", 1.8378], ["19", 2.3784], ["20", 1.0811], ["21", 0.4324], ["22", 1.4054], ["23", 1.4054], ["24", 0.1081], ["25", 0.2162], ["26", 0.2162], ["27", 0.3243], ["28", 0.973], ["29", 0.1081], ["30", 0.4324], ["31", 0.7568], ["32", 1.4054], ["33", 0.2162], ["34", 0.1081]]}
{"lang": "cpp", "distribution": [["7900", 0.8649], ["8000", 3.027], ["8100", 9.1892], ["8200", 19.7838], ["8300", 17.0811], ["8400", 4.4324], ["8500", 0.4324], ["8600", 0.973], ["8700", 0.3243], ["8800", 0.6486], ["8900", 0.4324], ["9000", 0.3243], ["9100", 0.7568], ["9200", 0.5405], ["9300", 0.8649], ["9400", 2.3784], ["9500", 3.1351], ["9600", 0.973], ["9700", 1.2973], ["9800", 0.2162], ["9900", 0.5405], ["10000", 0.6486], ["10100", 0.3243], ["10200", 0.5405], ["10300", 0.5405], ["10400", 0.8649], ["10500", 0.7568], ["10600", 0.6486], ["10700", 1.0811], ["10800", 0.8649], ["10900", 1.4054], ["11000", 1.2973], ["11100", 0.1081], ["11200", 0.2162], ["11300", 0.6486], ["11400", 0.5405], ["11500", 0.8649], ["11600", 1.4054], ["11700", 0.5405], ["11800", 2.1622], ["11900", 2.9189], ["12000", 5.7297], ["12100", 1.0811], ["12200", 0.3243], ["12300", 0.4324], ["12400", 0.3243], ["12600", 0.1081], ["12700", 0.1081], ["12800", 0.2162]]}
[ { "code": "class Solution {\n struct UnionFind {\n UnionFind() {\n std::iota(parents.begin(), parents.end(), 0);\n std::iota(chars.begin(), chars.end(), 0);\n }\n \n int find(int value) {\n if (parents[value] == value)\n return value...
37
[ { "code": "class Solution {\npublic:\n int par[26];\n \n int find(int x){\n if(par[x]==-1) return x;\n return par[x]=find(par[x]);\n }\n \n void Union(int x, int y) {\n x = find(x);\n y = find(y);\n \n if (x != y) \n par[max(x, y)] = min(x, ...
55
1,984
maximum-distance-between-a-pair-of-values
<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code>​​​​​​ and <code>nums2</code>​​​​​​.</p> <p>A pair of indices <code>(i, j)</code>, where <code>0 &lt;= i &lt; nums1.length</code> and <code>0 &lt;= j &lt; nums2.length</code>, is <strong>valid</strong> if both <code>i &lt;= j</code> and <code>nums1[i] &lt;= nums2[j]</code>. The <strong>distance</strong> of the pair is <code>j - i</code>​​​​.</p> <p>Return <em>the <strong>maximum distance</strong> of any <strong>valid</strong> pair </em><code>(i, j)</code><em>. If there are no valid pairs, return </em><code>0</code>.</p> <p>An array <code>arr</code> is <strong>non-increasing</strong> if <code>arr[i-1] &gt;= arr[i]</code> for every <code>1 &lt;= i &lt; arr.length</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5] <strong>Output:</strong> 2 <strong>Explanation:</strong> The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4). The maximum distance is 2 with pair (2,4). </pre> <p><strong class="example">Example 2:</strong></p> <pre> <strong>Input:</strong> nums1 = [2,2,2], nums2 = [10,10,1] <strong>Output:</strong> 1 <strong>Explanation:</strong> The valid pairs are (0,0), (0,1), and (1,1). The maximum distance is 1 with pair (0,1). </pre> <p><strong class="example">Example 3:</strong></p> <pre> <strong>Input:</strong> nums1 = [30,29,19,5], nums2 = [25,25,25,25,25] <strong>Output:</strong> 2 <strong>Explanation:</strong> The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4). The maximum distance is 2 with pair (2,4). </pre> <p>&nbsp;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li> <li><code>1 &lt;= nums1[i], nums2[j] &lt;= 10<sup>5</sup></code></li> <li>Both <code>nums1</code> and <code>nums2</code> are <strong>non-increasing</strong>.</li> </ul>
53.520252
Medium
[ "array", "two-pointers", "binary-search" ]
{"lang": "cpp", "distribution": [["48", 0.2193], ["52", 0.2193], ["55", 0.2193], ["60", 0.2193], ["61", 0.4386], ["62", 0.4386], ["63", 0.4386], ["67", 0.2193], ["71", 0.2193], ["72", 0.4386], ["73", 0.2193], ["87", 0.2193], ["90", 0.2193], ["99", 0.4386], ["101", 0.4386], ["102", 0.4386], ["103", 0.6579], ["104", 0.4386], ["105", 0.2193], ["106", 0.2193], ["107", 0.8772], ["108", 2.193], ["109", 1.3158], ["110", 1.7544], ["111", 2.4123], ["112", 3.7281], ["113", 2.193], ["114", 2.193], ["115", 2.6316], ["116", 2.8509], ["117", 3.5088], ["118", 2.6316], ["119", 1.9737], ["120", 4.1667], ["121", 4.1667], ["122", 4.386], ["123", 2.4123], ["124", 2.6316], ["125", 3.2895], ["126", 2.6316], ["127", 2.4123], ["128", 3.5088], ["129", 3.2895], ["130", 2.4123], ["131", 1.9737], ["132", 1.7544], ["133", 1.7544], ["134", 0.8772], ["135", 1.5351], ["136", 1.0965], ["137", 0.2193], ["138", 1.5351], ["139", 1.3158], ["140", 1.7544], ["141", 0.8772], ["142", 1.5351], ["143", 0.8772], ["144", 1.5351], ["145", 1.3158], ["146", 0.6579], ["147", 1.3158], ["148", 0.2193], ["149", 0.2193]]}
{"lang": "cpp", "distribution": [["100800", 0.6579], ["100900", 5.4825], ["101000", 15.1316], ["101100", 41.886]]}
[ { "code": "class Solution {\npublic:\n int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int ans = 0;\n int i = 0;\n int j = 0;\n while (i < nums1.size() && j < nums2.size()) {\n...
55
[ { "code": "class Solution {\npublic:\n int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n int res = 0;\n int i = 0, j = 0;\n while(i < nums1.size() && j < nums2.size()){\n while(j < nums2.size() && nums1[i] <= nums2[j]){\n j++;\n }\n ...
6
1,986
largest-color-value-in-a-directed-graph
"<p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> ed(...TRUNCATED)
49.838637
Hard
[ "hash-table", "dynamic-programming", "graph", "topological-sort", "memoization", "counting" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"258\", 0.5108], [\"270\", 0.2554], [\"282\", 0.3831], [\"(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"127939\", 0.6385000000000001], [\"129818\", 0.2554], [\"1(...TRUNCATED)
[{"code":"class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>(...TRUNCATED)
100
[{"code":"class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>(...TRUNCATED)
112
1,993
sum-of-all-subset-xor-totals
"<p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong>(...TRUNCATED)
87.778276
Easy
[ "array", "math", "backtracking", "bit-manipulation", "combinatorics", "enumeration" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"0\", 30.1166], [\"1\", 19.7487], [\"2\", 13.5099], [\"3\"(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"8413\", 75.763], [\"8841\", 3.0071000000000003], [\"9268\(...TRUNCATED)
[{"code":"class Solution {\n int solve(vector<int>& nums, int i, int xorr)\n {\n if(i =(...TRUNCATED)
72
[{"code":"class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums(...TRUNCATED)
82
2,505
number-of-good-paths
"<p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code>(...TRUNCATED)
56.26695
Hard
[ "array", "hash-table", "tree", "union-find", "graph", "sorting" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"221\", 0.64], [\"228\", 0.48], [\"235\", 0.8], [\"243\", (...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"130665\", 0.48], [\"132597\", 0.16], [\"134530\", 0.48], (...TRUNCATED)
[{"code":"#include <ranges>\n\nclass DisjointSet {\npublic:\n DisjointSet(int n, const vector<int(...TRUNCATED)
135
[{"code":"using P2I = pair<int, int>;\nclass Solution {\npublic:\n int numberOfGoodPaths(vector<i(...TRUNCATED)
120
3,276
minimum-number-of-pushes-to-type-word-ii
"<p>You are given a string <code>word</code> containing lowercase English letters.</p>\n\n<p>Telepho(...TRUNCATED)
80.708191
Medium
[ "hash-table", "string", "greedy", "sorting", "counting" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"4\", 0.023399999999999997], [\"6\", 0.0109], [\"8\", 0.01(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"8530\", 0.0265], [\"8790\", 0.0031], [\"9050\", 0.0047], (...TRUNCATED)
[{"code":"struct Solution {\n int minimumPushes(string_view input) {\n int i = 0;\n (...TRUNCATED)
104
[{"code":"struct Solution {\n int minimumPushes(string_view input) {\n int i;\n int(...TRUNCATED)
80
2,076
sum-of-digits-of-string-after-convert
"<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <c(...TRUNCATED)
74.965412
Easy
[ "string", "simulation" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"0\", 41.3082], [\"1\", 0.024], [\"2\", 3.8779], [\"3\", 1(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"7500\", 0.0017], [\"7600\", 0.1253], [\"7700\", 2.0247], (...TRUNCATED)
[{"code":"class Solution {\npublic:\n int getLucky(string s, int k) {\n int len = s.length(...TRUNCATED)
2
[{"code":"int sumDigits(int num) {\n int sum = 0;\n while (num) {\n sum += num % 10;\n (...TRUNCATED)
45
2,251
number-of-ways-to-divide-a-long-corridor
"<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <(...TRUNCATED)
49.341445
Hard
[ "math", "string", "dynamic-programming" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"51\", 1.1365], [\"64\", 1.1365], [\"76\", 0.2273], [\"89\(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"28675\", 1.1362999999999999], [\"33425\", 39.545500000000(...TRUNCATED)
[{"code":"class Solution {\npublic:\n int numberOfWays(string corridor) {\n ios_base::sync(...TRUNCATED)
74
[{"code":"class Solution {\npublic:\n int numberOfWays(string_view corridor) {\n constexpr(...TRUNCATED)
43
2,271
rearrange-array-elements-by-sign
"<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</stro(...TRUNCATED)
84.072132
Medium
[ "array", "two-pointers", "simulation" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"61\", 0.008], [\"62\", 0.004], [\"64\", 0.004], [\"65\", (...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"124617\", 0.064], [\"124852\", 0.0721], [\"125087\", 0.26(...TRUNCATED)
[{"code":"class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios(...TRUNCATED)
120
[{"code":"class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n st(...TRUNCATED)
108
2,519
find-the-original-array-of-prefix-xor
"<p>You are given an <strong>integer</strong> array <code>pref</code> of size <code>n</code>. Find a(...TRUNCATED)
88.04974
Medium
[ "array", "bit-manipulation" ]
"{\"lang\": \"cpp\", \"distribution\": [[\"30\", 0.0437], [\"31\", 0.0437], [\"33\", 0.0437], [\"34\(...TRUNCATED)
"{\"lang\": \"cpp\", \"distribution\": [[\"78300\", 0.3493], [\"78400\", 1.5721], [\"78500\", 8.821](...TRUNCATED)
[{"code":"class Solution {\npublic:\n vector<int> findArray(vector<int>& v) {\n ios::sync_(...TRUNCATED)
65
[{"code":"#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\")\nclass Solution {\npublic:\n(...TRUNCATED)
19
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
7