question_id
int64
1
3.58k
name
stringlengths
3
77
content
stringlengths
516
21.8k
acRate
float64
9.94
93
difficulty
stringclasses
3 values
topics
listlengths
0
10
runtimeDistribution
stringlengths
53
2.38k
memoryDistribution
stringlengths
54
2.14k
rt_list
listlengths
1
156
rt_solution_count
int64
1
156
mm_list
listlengths
1
154
mm_solution_count
int64
1
154
94
binary-tree-inorder-traversal
<p>Given the <code>root</code> of a binary tree, return <em>the inorder traversal of its nodes&#39; values</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p> <p><strong>Output:</stro...
77.060963
Easy
[ "stack", "tree", "depth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["13", 0.0044], ["14", 0.0044], ["15", 0.0355], ["16", 0.04], ["17", 0.0355], ["18", 0.1021], ["19", 0.1776], ["20", 0.1598], ["21", 0.1865], ["22", 0.6215], ["23", 0.657], ["24", 0.8967], ["25", 1.061], ["26", 2.4771], ["27", 1.9], ["28", 2.1042], ["29", 3.4138], ["30", 5.9709], ["...
{"lang": "python3", "distribution": [["15900", 0.0044], ["16000", 0.0089], ["16100", 0.0444], ["16200", 0.3063], ["16300", 5.1008], ["16400", 26.5027], ["16500", 49.6449]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n\n result = []\n def inorderTraversal(self, root: Optional[TreeNode]) -> List[in...
51
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n tlist=...
11
95
unique-binary-search-trees-ii
<p>Given an integer <code>n</code>, return <em>all the structurally unique <strong>BST&#39;</strong>s (binary search trees), which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>. Return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><stron...
58.659893
Medium
[ "dynamic-programming", "backtracking", "tree", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["28", 0.0394], ["29", 0.0394], ["30", 0.0394], ["31", 0.0788], ["32", 0.1969], ["33", 0.1182], ["34", 0.3151], ["35", 0.6696], ["36", 0.8665], ["37", 0.7877], ["38", 1.2603], ["39", 1.9299], ["40", 2.5601], ["41", 2.6388], ["42", 2.4813], ["43", 4.0961], ["44", 5.4352], ["45", 4.37...
{"lang": "python3", "distribution": [["16700", 0.0394], ["16800", 0.0394], ["17000", 0.1969], ["17100", 1.3391], ["17200", 5.2777], ["17300", 14.297], ["17400", 11.0673], ["17500", 1.5754], ["17600", 6.538], ["17700", 13.2336], ["17800", 13.785], ["17900", 9.7676], ["18000", 6.9712], ["18100", 6.9319], ["18200", 1.9693...
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def generateTrees(self, n: int) -> List[Optional[TreeNode]]:\n\n ans = []\n...
44
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def generateTrees(self, n: int) -> List[Optional[TreeNode]]:\n def generate...
26
96
unique-binary-search-trees
<p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST&#39;</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <i...
61.559178
Medium
[ "math", "dynamic-programming", "tree", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["14", 0.0237], ["16", 0.0237], ["17", 0.0237], ["18", 0.0474], ["19", 0.0948], ["20", 0.3081], ["21", 0.1185], ["22", 0.545], ["23", 0.4502], ["24", 1.6588], ["25", 0.9242], ["26", 2.3223], ["27", 1.7299], ["28", 3.5071], ["29", 3.6256], ["30", 5.1185], ["31", 4.0995], ["32", 6.208...
{"lang": "python3", "distribution": [["16100", 0.0237], ["16200", 0.6398], ["16300", 8.1991], ["16400", 25.6635], ["16500", 46.4929]]}
[ { "code": "class Solution:\n def numTrees(self, n: int) -> int:\n if n == 0:\n return 1\n\n if n == 1:\n return 1\n\n if n == 2:\n return 2\n \n num_trees = [0 for _ in range(n+1)]\n num_trees[0] = 1\n num_trees[1] = 1\n ...
40
[ { "code": "class Solution:\n\n def numTrees(self, n: int) -> int:\n global memo\n memo = [[0 for i in range(n+1)] for j in range(n+1)]\n return self.count(1, n)\n \n def count(self, lo, hi):\n if lo > hi:\n return 1\n if memo[lo][hi] != 0:\n ...
8
97
interleaving-string
<p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p> <p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and...
40.592713
Medium
[ "string", "dynamic-programming" ]
{"lang": "python3", "distribution": [["12", 0.0124], ["20", 0.0124], ["22", 0.0497], ["23", 0.0745], ["24", 0.1117], ["25", 0.1614], ["26", 0.2607], ["27", 0.3972], ["28", 0.571], ["29", 0.4469], ["30", 1.2537], ["31", 1.5765], ["32", 1.3654], ["33", 1.8247], ["34", 3.3143], ["35", 3.3764], ["36", 3.2274], ["37", 4.096...
{"lang": "python3", "distribution": [["15600", 0.0124], ["16200", 0.0248], ["16300", 0.1986], ["16400", 1.6261], ["16500", 7.2244], ["16600", 16.2612], ["16700", 21.5367], ["16800", 7.4851], ["16900", 1.8371], ["17000", 1.5144], ["17100", 1.142], ["17200", 2.0482], ["17300", 9.5333], ["17400", 9.8684], ["17500", 5.3625...
[ { "code": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:\n if s1 == \"\":\n return s2 == s3\n if s2 == \"\":\n return s1 == s3\n if s1+s2==s3:\n return True\n if s2+s1==s3:\n return True\n if len(s3)...
60
[ { "code": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:\n m, n = len(s1), len(s2)\n if m + n != len(s3):\n return False\n dp = [[False] * (n + 1) for _ in range(m + 1)]\n dp[0][0] = True\n for i in range(1, m + 1):\n dp[...
35
98
validate-binary-search-tree
<p>Given the <code>root</code> of a binary tree, <em>determine if it is a valid binary search tree (BST)</em>.</p> <p>A <strong>valid BST</strong> is defined as follows:</p> <ul> <li>The left <span data-keyword="subtree">subtree</span> of a node contains only nodes with keys <strong>less than</strong> the node&#39;s...
33.412998
Medium
[ "tree", "depth-first-search", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["17", 0.0036], ["19", 0.0073], ["20", 0.0109], ["21", 0.0109], ["22", 0.0435], ["23", 0.0617], ["24", 0.1052], ["25", 0.0508], ["26", 0.2249], ["27", 0.3445], ["28", 0.5549], ["29", 0.515], ["30", 0.874], ["31", 1.3201], ["32", 2.0201], ["33", 1.7844], ["34", 2.3791], ["35", 3.5542...
{"lang": "python3", "distribution": [["17700", 0.0036], ["17800", 0.0036], ["17900", 0.0181], ["18000", 0.058], ["18100", 0.7943], ["18200", 9.3425], ["18300", 27.8026], ["18400", 46.0414]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n def validate(node...
56
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\ndef is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] >= lst[i + 1]:\n r...
12
99
recover-binary-search-tree
<p>You are given the <code>root</code> of a binary search tree (BST), where the values of <strong>exactly</strong> two nodes of the tree were swapped by mistake. <em>Recover the tree without changing its structure</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asset...
54.262346
Medium
[ "tree", "depth-first-search", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["39", 0.337], ["40", 0.2106], ["41", 0.337], ["42", 0.2527], ["43", 0.5055], ["44", 0.4634], ["45", 0.5476], ["46", 1.011], ["47", 1.4322], ["48", 1.6007], ["49", 1.4322], ["50", 2.8644], ["51", 2.4853], ["52", 3.7068], ["53", 3.8753], ["54", 5.0969], ["55", 5.0969], ["56", 4.8863]...
{"lang": "python3", "distribution": [["16500", 0.0421], ["16600", 1.4743], ["16700", 15.417], ["16800", 35.1306], ["16900", 38.9217]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def recoverTree(self, root):\n \"\"\"\n :type root: ...
48
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def enumerate_nodes(self, root):\n if root.left is not None:\n r...
9
100
same-tree
<p>Given the roots of two binary trees <code>p</code> and <code>q</code>, write a function to check if they are the same or not.</p> <p>Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <...
63.293653
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["12", 0.0093], ["14", 0.0093], ["15", 0.0309], ["16", 0.0247], ["17", 0.0494], ["18", 0.0895], ["19", 0.2099], ["20", 0.1451], ["21", 0.2099], ["22", 0.6266], ["23", 0.7531], ["24", 0.7377], ["25", 1.0], ["26", 2.5958], ["27", 2.0741], ["28", 2.0309], ["29", 3.2131], ["30", 6.1483]...
{"lang": "python3", "distribution": [["16000", 0.0031], ["16100", 0.0278], ["16200", 0.0586], ["16300", 0.7871], ["16400", 14.3369], ["16500", 48.0077]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:\n ...
49
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:\n\n ...
9
1
two-sum
<p>Given an array of integers <code>nums</code>&nbsp;and an integer <code>target</code>, return <em>indices of the two numbers such that they add up to <code>target</code></em>.</p> <p>You may assume that each input would have <strong><em>exactly</em> one solution</strong>, and you may not use the <em>same</em> elemen...
53.738751
Easy
[ "array", "hash-table" ]
{"lang": "python3", "distribution": [["36", 35.791399999999996], ["77", 24.876300000000008], ["118", 0.0572], ["159", 0.0434], ["200", 0.06270000000000002], ["241", 0.05840000000000001], ["283", 0.228], ["324", 0.3168000000000001], ["365", 0.9585], ["406", 0.23110000000000006], ["447", 0.0835], ["488", 0.17149999999999...
{"lang": "python3", "distribution": [["15600", 0.0006], ["16200", 0.0013], ["16300", 0.0077], ["16400", 0.0232], ["16500", 0.0529], ["16600", 0.0174], ["16700", 0.0045], ["16800", 0.0103], ["16900", 0.0206], ["17000", 0.0619], ["17100", 0.9594], ["17200", 8.7656], ["17300", 14.5324], ["17400", 13.3647], ["17500", 1.406...
[ { "code": "class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n f = open('user.out', 'w')\n print('''[1, 0]\n [2, 1]\n [1, 0]\n [2, 0]\n [2, 1]\n [3, 0]\n [2, 0]\n [4, 2]\n [2, 1]\n [1, 0]\n [3, 2]...
152
[ { "code": "class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n f = open('user.out', 'w')\n print('''[1, 0]\n [2, 1]\n [1, 0]\n [2, 0]\n [2, 1]\n [3, 0]\n [2, 0]\n [4, 2]\n [2, 1]\n [1, 0]\n [3, 2]...
31
2
add-two-numbers
<p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The digits are stored in <strong>reverse order</strong>, and each of their nodes contains a single digit. Add the two numbers and return the sum&nbsp;as a linked list.</p> <p>You may assume the two numbers do not conta...
44.08585
Medium
[ "linked-list", "math", "recursion" ]
{"lang": "python3", "distribution": [["26", 0.002], ["27", 0.0061], ["28", 0.0061], ["29", 0.002], ["30", 0.0121], ["31", 0.0182], ["32", 0.0061], ["33", 0.0243], ["34", 0.0567], ["35", 0.0971], ["36", 0.0931], ["37", 0.17], ["38", 0.34], ["39", 0.336], ["40", 0.3967], ["41", 0.5141], ["42", 1.1111], ["43", 0.9755], ["...
{"lang": "python3", "distribution": [["16000", 0.0061], ["16100", 0.0101], ["16200", 0.0283], ["16300", 0.166], ["16400", 2.3881], ["16500", 23.2135], ["16600", 46.8802]]}
[ { "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:\n dummy = ListNode()\n...
65
[ { "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:\n dummy = ListNode()\n...
7
3
longest-substring-without-repeating-characters
<p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abcabcbb&quot; <strong>...
35.43496
Medium
[ "hash-table", "string", "sliding-window" ]
{"lang": "python3", "distribution": [["23", 0.0091], ["29", 0.1174], ["35", 1.3880000000000001], ["41", 6.6044], ["47", 18.7271], ["53", 30.679500000000004], ["60", 15.3074], ["66", 4.734], ["72", 2.2921], ["78", 1.5363000000000002], ["84", 0.8128], ["91", 0.4515], ["97", 0.32509999999999994], ["103", 0.2903], ["109", ...
{"lang": "python3", "distribution": [["15900", 0.0013], ["16000", 0.0026], ["16100", 0.0116], ["16200", 0.0232], ["16300", 0.1109], ["16400", 1.219], ["16500", 18.1234], ["16600", 40.8235], ["16700", 31.9062]]}
[ { "code": "class Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n if s==\"\": return 0\n longs=s[0]\n start=0\n end=1\n maxlen=1\n while(end<len(s)):\n if s[end] not in longs:\n longs+=s[end]\n else:\n whi...
153
[ { "code": "class Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n if not s:\n return 0\n if len(set(s))==1:\n return 1\n \n unique=set()\n slen=0\n start=0\n\n for i in range(len(s)):\n while s[i] in unique:\n ...
14
4
median-of-two-sorted-arrays
<p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p> <p>The overall run time complexity should be <code>O(log (m+n))</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:<...
41.439262
Hard
[ "array", "binary-search", "divide-and-conquer" ]
{"lang": "python3", "distribution": [["29", 0.0058], ["30", 0.0058], ["31", 0.0029], ["32", 0.0029], ["33", 0.0029], ["34", 0.0146], ["35", 0.0117], ["36", 0.0088], ["37", 0.0088], ["38", 0.0029], ["39", 0.0233], ["40", 0.0146], ["41", 0.0409], ["42", 0.0379], ["43", 0.0263], ["44", 0.0263], ["45", 0.0379], ["46", 0.03...
{"lang": "python3", "distribution": [["16100", 0.0029], ["16200", 0.0088], ["16300", 0.0058], ["16400", 0.0263], ["16500", 0.0817], ["16600", 0.5194], ["16700", 7.3886], ["16800", 28.5827], ["16900", 43.0301], ["17000", 14.4154]]}
[ { "code": "class Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:\n arr=nums1+nums2\n arr.sort()\n l=len(arr)\n if l%2==1:\n return arr[(l-1)//2]\n else:\n return (arr[(l-2)//2]+arr[l//2])/2\n\nwith open(\"user...
93
[ { "code": "import statistics as stat\n\nclass Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:\n all_nums = nums1 + nums2\n all_nums.sort()\n return stat.median(all_nums)\n \n #if len(all_nums) % 2 == 0:\n # print(all_nums...
15
5
longest-palindromic-substring
<p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = ...
34.434009
Medium
[ "two-pointers", "string", "dynamic-programming" ]
{"lang": "python3", "distribution": [["85", 4.451900000000003], ["191", 3.1727999999999996], ["297", 38.732899999999994], ["403", 7.024599999999999], ["509", 3.247099999999999], ["615", 2.0216000000000007], ["721", 0.7827999999999992], ["827", 0.3468999999999999], ["933", 0.3341999999999999], ["1039", 0.326499999999999...
{"lang": "python3", "distribution": [["16000", 0.0076], ["16100", 0.0381], ["16200", 0.1831], ["16300", 0.6153], ["16400", 6.3331], ["16500", 19.7086], ["16600", 34.5918], ["16700", 15.6866], ["16800", 2.5907], ["16900", 0.8568], ["17000", 0.4754], ["17100", 0.4042], ["17200", 0.4195], ["17300", 0.2237], ["17400", 0.09...
[ { "code": "class Solution:\n def longestPalindrome(self, s: str) -> str:\n return longestPalindrome_3(s)\n\n\ndef longestPalindrome_1(s: str) -> str:\n return max((pal for pal in subsequences(s) if is_pal(pal)), key=len)\n\ndef subsequences(s: str) -> list[str]:\n return (s[i:j] for i in range(l...
150
[ { "code": "class Solution:\n def longestPalindrome(self, s: str) -> str:\n resP = \"\"\n resLen = 0\n\n for i in range(len(s)):\n l, r = i, i\n\n while l >= 0 and r < len(s) and s[l] == s[r]:\n if (r - l + 1) > resLen:\n resP = s[l ...
85
6
zigzag-conversion
<p>The string <code>&quot;PAYPALISHIRING&quot;</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p> <pre> P A H N A P L S I I G Y I R </pre> <p>And then read line by line: <code>&quot;PAHNAPLSIIGYIR&quot;<...
49.271863
Medium
[ "string" ]
{"lang": "python3", "distribution": [["25", 0.0877], ["30", 0.7676000000000001], ["36", 3.4871], ["41", 14.2003], ["46", 22.2161], ["51", 23.3401], ["57", 13.7726], ["62", 6.047499999999999], ["67", 1.7545], ["72", 0.9924], ["78", 0.6251], ["83", 0.5702], ["88", 0.34540000000000004], ["94", 0.3235], ["99", 0.2302999999...
{"lang": "python3", "distribution": [["15900", 0.0055], ["16200", 0.0164], ["16300", 0.1097], ["16400", 2.0231], ["16500", 12.1333], ["16600", 26.0924], ["16700", 29.3602], ["16800", 15.1434], ["16900", 4.3588], ["17000", 1.4474], ["17100", 0.3893], ["17200", 0.1864], ["17300", 0.0822], ["17400", 0.0603], ["17500", 0.1...
[ { "code": "class Solution:\n def convert(self, s: str, numRows: int) -> str:\n if numRows == 1:\n return s\n \n # Initialize an array of strings to hold characters for each row\n rows = [''] * numRows\n curr_row = 0\n going_down = False\n \n ...
150
[ { "code": "from itertools import chain\nclass Solution:\n def convert(self, s: str, numRows: int) -> str:\n if numRows == 1 or numRows >= len(s):\n return s\n if numRows == 2:\n return s[0::2] + s[1::2]\n elif numRows >= 3:\n rows = [''] * numRows\n ...
78
7
reverse-integer
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
29.150576
Medium
[ "math" ]
{"lang": "python3", "distribution": [["11", 0.0034], ["12", 0.0068], ["15", 0.0204], ["16", 0.0273], ["17", 0.0102], ["18", 0.0818], ["19", 0.1295], ["20", 0.2215], ["21", 0.0716], ["22", 0.3442], ["23", 0.593], ["24", 0.8008], ["25", 0.5146], ["26", 1.0564], ["27", 2.0515], ["28", 2.5423], ["29", 1.98], ["30", 2.6275]...
{"lang": "python3", "distribution": [["16000", 0.0034], ["16100", 0.0136], ["16200", 0.1295], ["16300", 2.4605], ["16400", 17.4857], ["16500", 37.9124], ["16600", 36.9854]]}
[ { "code": "class Solution:\n def reverse(self, x: int) -> int:\n sign = -1 if x < 0 else 1\n res = 0\n n = abs(x)\n while n != 0:\n res = res * 10 + n % 10\n if res > 2**31-1:\n return 0\n n //= 10\n \n return res * sig...
55
[ { "code": "class Solution:\n def reverse(self, x: int) -> int:\n \n MAX_INT = 2**31 -1\n\n negative = x < 0\n x = abs(x)\n rev = 0\n while x != 0:\n\n x, mod = divmod(x, 10)\n\n rev = rev * 10 + mod\n\n if rev > MAX_INT:\n ...
11
8
string-to-integer-atoi
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
17.90882
Medium
[ "string" ]
{"lang": "python3", "distribution": [["14", 0.0063], ["15", 0.0063], ["16", 0.0126], ["17", 0.0063], ["18", 0.0316], ["19", 0.0631], ["20", 0.0695], ["21", 0.0568], ["22", 0.1831], ["23", 0.3347], ["24", 0.3915], ["25", 0.3284], ["26", 0.9156], ["27", 1.143], ["28", 1.2629], ["29", 1.3008], ["30", 3.069], ["31", 2.9742...
{"lang": "python3", "distribution": [["15900", 0.0063], ["16100", 0.0063], ["16200", 0.0253], ["16300", 0.9283], ["16400", 9.8383], ["16500", 27.1217], ["16600", 43.338]]}
[ { "code": "class Solution:\n def myAtoi(self, s: str) -> int:\n sign = 1\n result = 0\n index = 0\n n = len(s)\n\n INT_MAX = pow(2, 31) - 1\n INT_MIN = -pow(2, 31)\n\n # Discard all spaces from the beginning of the input string.\n while index < n and s[...
52
[ { "code": "class Solution:\n def myAtoi(self, s: str) -> int:\n s = s.strip()\n if not s:\n return 0\n\n sign = -1 if s[0] == '-' else 1\n if s[0] in {'-', '+'}:\n s = s[1:]\n\n num = 0\n\n for c in s:\n if not c.isdigit():\n break\n num = num * 10 + int(c)\n i...
11
9
palindrome-number
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
57.495246
Easy
[ "math" ]
{"lang": "python3", "distribution": [["19", 0.0015], ["20", 0.0046], ["23", 0.0153], ["24", 0.0061], ["25", 0.0046], ["26", 0.0077], ["27", 0.0307], ["28", 0.043], ["29", 0.0246], ["30", 0.0598], ["31", 0.1565], ["32", 0.1274], ["33", 0.0752], ["34", 0.2608], ["35", 0.4312], ["36", 0.4787], ["37", 0.3238], ["38", 0.758...
{"lang": "python3", "distribution": [["15700", 0.0015], ["15900", 0.0031], ["16000", 0.0077], ["16100", 0.0153], ["16200", 0.0951], ["16300", 0.9697], ["16400", 15.1292], ["16500", 43.9591], ["16600", 34.3322]]}
[ { "code": "class Solution:\n def isPalindrome(self, x: int) -> bool:\n x = str(x)\n return x == x[::-1]\n", "runtime": "19" }, { "code": "class Solution:\n def isPalindrome(self, x: int) -> bool:\n x = str(x)\n return x == x[::-1]\n ", "runtime": "20" }...
86
[ { "code": "class Solution:\n def isPalindrome(self, x: int) -> bool:\n x2 = str(x)\n for i in range(len(x2)):\n if x2[i] != x2[len(x2)-i-1]:\n return False\n return True\n \n ", "memory": "15900" }, { "code": "class Solution:\n d...
12
10
regular-expression-matching
<p>Given an input string <code>s</code>&nbsp;and a pattern <code>p</code>, implement regular expression matching with support for <code>&#39;.&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;.&#39;</code> Matches any single character.​​​​</li> <li><code>&#39;*&#39;</code> Matches zero or more...
28.382487
Hard
[ "string", "dynamic-programming", "recursion" ]
{"lang": "python3", "distribution": [["75", 79.11500000000014], ["191", 1.7083000000000017], ["307", 3.8160000000000007], ["423", 0.30219999999999986], ["539", 0.0784], ["654", 0.0784], ["770", 0.0112], ["886", 0.0112], ["1002", 0.0448], ["1118", 0.0112], ["1233", 0.0112], ["1349", 0.0112], ["1465", 0.0224], ["1581", 0...
{"lang": "python3", "distribution": [["16000", 0.0112], ["16100", 0.0558], ["16200", 0.1674], ["16300", 1.1492], ["16400", 6.8169], ["16500", 18.1412], ["16600", 27.1115], ["16700", 12.9309], ["16800", 10.8446], ["16900", 13.7119]]}
[ { "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:\n \n # TOP-Down Memoization\n\n cache = {}\n\n def dfs(i, j):\n if (i, j) in cache:\n return cache[(i, j)]\n if i >= len(s) and j >= len(p):\n return True\n ...
115
[ { "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:\n dp = [[False] * (len(p) + 1) for _ in range(len(s) + 1)]\n\n dp[0][0] = True\n\n for j in range(2, len(p) + 1, 2):\n if p[j - 1] == '*':\n dp[0][j] = True\n else:\n ...
17
309
best-time-to-buy-and-sell-stock-with-cooldown
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the foll...
59.122066
Medium
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["32", 28.060899999999997], ["49", 61.8133], ["66", 1.3134], ["83", 0.0423], ["100", 0.0141], ["117", 0.0141], ["134", 0.0282], ["151", 0.0423], ["168", 0.0141], ["185", 0.0141], ["202", 0.0141], ["219", 0.0141], ["236", 0.0141], ["253", 0.0141], ["270", 0.0141], ["287", 0.0141], ["...
{"lang": "python3", "distribution": [["16300", 0.0141], ["16400", 0.0141], ["16500", 0.0989], ["16600", 0.9038], ["16700", 7.1318], ["16800", 13.4303], ["16900", 7.9509], ["17000", 5.1405], ["17100", 4.3073], ["17200", 4.1802], ["17300", 3.2764], ["17400", 1.3134], ["17500", 1.7512], ["17600", 1.5393], ["17700", 0.6496...
[ { "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:\n self.dp=[{\"nothing\":-1,\"bought\":-1,\"sold\":-1}for i in range(0,len(prices)+1)]\n self.dp[len(prices)]={\"nothing\":0,\"bought\":0,\"sold\":0}\n return self.rec(prices,0,\"nothing\")\n\n def rec(self,pri...
121
[ { "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:\n n = len(prices)\n dp = [0 for _ in range(n+2)]\n\n for buy in range(n-1, -1, -1):\n max_profit = 0\n for sell in range(buy+1, n):\n max_profit = max(max_profit, prices[sell]...
75
310
minimum-height-trees
<p>A tree is an undirected graph in which any two vertices are connected by&nbsp;<i>exactly</i>&nbsp;one path. In other words, any connected graph without simple cycles is a tree.</p> <p>Given a tree of <code>n</code> nodes&nbsp;labelled from <code>0</code> to <code>n - 1</code>, and an array of&nbsp;<code>n - 1</code...
41.869078
Medium
[ "depth-first-search", "breadth-first-search", "graph", "topological-sort" ]
{"lang": "python3", "distribution": [["134", 0.0831], ["168", 0.0277], ["202", 0.0277], ["235", 0.0277], ["269", 0.0555], ["303", 0.0277], ["337", 0.111], ["370", 4.328399999999999], ["404", 55.7991], ["438", 23.03], ["471", 4.1061000000000005], ["505", 1.1369], ["539", 0.7209999999999999], ["572", 0.388], ["606", 0.02...
{"lang": "python3", "distribution": [["22100", 0.0277], ["23100", 0.0277], ["25000", 0.0277], ["25500", 0.0277], ["25700", 0.0277], ["25900", 0.1387], ["26000", 0.6382], ["26100", 1.97], ["26200", 3.4684], ["26300", 7.3529], ["26400", 6.9645], ["26500", 5.5216], ["26600", 3.0799], ["26700", 3.0522], ["26800", 1.97], ["...
[ { "code": "class Solution:\n def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:\n if n == 1:\n return [0]\n\n graph = [[] for _ in range(n)]\n for u, v in edges:\n graph[u].append(v)\n graph[v].append(u)\n\n leaves = [i for ...
89
[ { "code": "class Solution:\n def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:\n if n == 1:\n return [0]\n\n graph = [[] for _ in range(n)]\n for u, v in edges:\n graph[u].append(v)\n graph[v].append(u)\n\n leaves = [i for ...
79
312
burst-balloons
<p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p> <p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums...
59.82926
Hard
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["1300", 0.9663000000000004], ["1393", 0.0716], ["1486", 0.0358], ["1579", 0.358], ["1673", 0.358], ["1766", 0.2506], ["1859", 0.1432], ["1952", 0.4653], ["2045", 0.3221], ["2138", 0.179], ["2231", 0.358], ["2324", 0.2148], ["2418", 1.0735000000000001], ["2511", 3.1481000000000003],...
{"lang": "python3", "distribution": [["17501", 0.1431], ["17705", 0.0715], ["17909", 0.1073], ["18113", 0.2861], ["18316", 4.7194], ["18520", 26.4927], ["18724", 0.4648], ["18928", 0.1073], ["19131", 0.1788], ["19335", 0.143], ["19539", 0.2145], ["19743", 0.1788], ["19946", 0.143], ["20150", 0.0358], ["20354", 0.0715],...
[ { "code": "class Solution:\n def maxCoins(self, nums: List[int]) -> int:\n\n nums = [1] + [x for x in nums if x != 0] + [1]\n n = len(nums)\n dp = [[0] * n for _ in range(n)]\n\n for r in range(2, n):\n for l in range(r - 2, -1, -1):\n adj = nums[l] * num...
155
[ { "code": "class Solution:\n def maxCoins(self, nums: List[int]) -> int:\n n = len(nums)\n nums = [1] + nums + [1]\n dp = [[0] * (n + 2) for _ in range(n + 2)]\n for i in range(n, -1, -1):\n for j in range(i + 1, n + 2):\n for k in range(i + 1, j):\n ...
98
316
remove-duplicate-letters
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
50.146812
Medium
[ "string", "stack", "greedy", "monotonic-stack" ]
{"lang": "python3", "distribution": [["20", 0.2332], ["21", 0.0466], ["22", 0.1399], ["23", 0.1399], ["24", 0.7463], ["25", 0.4664], ["26", 0.4664], ["27", 0.8396], ["28", 0.9328], ["29", 1.3526], ["30", 2.1455], ["31", 2.3321], ["32", 3.4049], ["33", 4.1978], ["34", 3.6381], ["35", 4.8974], ["36", 6.2966], ["37", 5.97...
{"lang": "python3", "distribution": [["16100", 0.0466], ["16300", 0.3265], ["16400", 6.3433], ["16500", 23.5075], ["16600", 43.0037], ["16700", 20.6157]]}
[ { "code": "class Solution:\n def removeDuplicateLetters(self, s: str) -> str:\n n = len(s)\n last_idx_arr = [-1] * 26\n for i in range(n):\n last_idx_arr[ord(s[i]) - ord('a')] = i\n\n stack = []\n used_arr = [False] * 26\n for i in range(n):\n c...
54
[ { "code": "class Solution:\n def removeDuplicateLetters(self, s: str) -> str:\n ans = []\n count = collections.Counter(s)\n used = [False] * 26\n\n for c in s:\n count[c] -= 1\n if used[string.ascii_lowercase.index(c)]:\n continue\n while ans and ans[-1] > c and count[ans[-1]]...
9
299
bulls-and-cows
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
50.631182
Medium
[ "hash-table", "string", "counting" ]
{"lang": "python3", "distribution": [["18", 0.0639], ["21", 0.0639], ["25", 0.0639], ["26", 0.2554], ["27", 0.447], ["28", 0.2554], ["29", 0.3193], ["30", 0.7663], ["31", 1.1494], ["32", 1.1494], ["33", 1.5326], ["34", 2.8097], ["35", 2.8097], ["36", 2.9374], ["37", 3.7676], ["38", 4.5338], ["39", 6.0026], ["40", 4.661...
{"lang": "python3", "distribution": [["16200", 0.1916], ["16300", 1.0217], ["16400", 11.175], ["16500", 31.4815], ["16600", 42.401]]}
[ { "code": "class Solution:\n def getHint(self, secret: str, guess: str) -> str:\n sDir = defaultdict(int)\n gDir = defaultdict(int)\n n = len(secret)\n x = 0\n for i in range(n):\n s = secret[i]\n g = guess[i]\n if s == g:\n x...
59
[ { "code": "class Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bulls = 0\n cows = 0\n secret_set = defaultdict(int) # counts of all nums in secret\n\n for c in secret:\n secret_set[c] += 1\n\n print(secret_set)\n\n for i in range(len(sec...
10
300
longest-increasing-subsequence
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
56.271682
Medium
[ "array", "binary-search", "dynamic-programming" ]
{"lang": "python3", "distribution": [["57", 20.864900000000002], ["102", 0.9743000000000002], ["148", 0.23629999999999993], ["193", 0.15249999999999994], ["238", 0.15739999999999998], ["283", 0.08759999999999996], ["328", 0.0092], ["374", 0.041499999999999995], ["419", 0.023], ["464", 0.050699999999999995], ["509", 0.0...
{"lang": "python3", "distribution": [["16100", 0.0093], ["16200", 0.0186], ["16300", 0.0464], ["16400", 0.1067], ["16500", 0.1902], ["16600", 0.812], ["16700", 7.456], ["16800", 22.6001], ["16900", 39.3588], ["17000", 16.2019], ["17100", 2.0136], ["17200", 0.6124], ["17300", 0.2273], ["17400", 0.1717], ["17500", 0.1206...
[ { "code": "class Solution:\n def lengthOfLIS(self, nums: List[int]) -> int:\n p = 1\n for i in range(1, len(nums)):\n n = nums[i]\n if n > nums[p - 1]: p += 1\n nums[bisect_left(nums, n, hi = p - 1)] = n\n return p\n\nwith open(\"user.out\", \"w\") as f:\...
151
[ { "code": "class Solution:\n def lengthOfLIS(self, nums: List[int]) -> int:\n n = len(nums)\n dp = [1] * n\n max_len = 1\n for i in range(1, n):\n for j in range(i):\n if nums[i] > nums[j]:\n dp[i] = max(dp[i], dp[j] + 1)\n m...
49
301
remove-invalid-parentheses
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
48.542114
Hard
[ "string", "backtracking", "breadth-first-search" ]
{"lang": "python3", "distribution": [["50", 16.404099999999996], ["98", 17.747899999999998], ["147", 12.326000000000008], ["196", 4.958199999999997], ["244", 2.0383], ["293", 0.6483000000000001], ["342", 0.6948000000000001], ["390", 0.9265000000000001], ["439", 0.3241], ["487", 0.2315], ["536", 0.0926], ["585", 0.1852]...
{"lang": "python3", "distribution": [["16200", 0.0463], ["16300", 0.3244], ["16400", 1.6219], ["16500", 9.7312], ["16600", 18.304], ["16700", 17.0992], ["16800", 8.1557], ["16900", 4.4949], ["17000", 2.1779], ["17100", 1.2975], ["17200", 6.9045], ["17300", 8.1094], ["17400", 1.1585], ["17500", 1.1121], ["17600", 1.6682...
[ { "code": "class Solution:\n def removeInvalidParentheses(self, s: str) -> List[str]:\n # to find unique result, for consecutive same brackets, we should treat them as a group\n groups = []\n n = len(s)\n # now we find the minimum of removes\n removel = remover = 0\n ...
122
[ { "code": "class Solution:\n def __init__(self):\n self.valid_expressions = None\n self.min_removed = None\n \n def reset(self):\n self.valid_expressions = set()\n self.min_removed = float('inf')\n \n def backtrack(self, string, index, left, right, expr, remove_cnt):\n...
53
303
range-sum-query-immutable
<p>Given an integer array <code>nums</code>, handle multiple queries of the following type:</p> <ol> <li>Calculate the <strong>sum</strong> of the elements of <code>nums</code> between indices <code>left</code> and <code>right</code> <strong>inclusive</strong> where <code>left &lt;= right</code>.</li> </ol> <p>Imple...
64.994138
Easy
[ "array", "design", "prefix-sum" ]
{"lang": "python3", "distribution": [["59", 60.3554], ["89", 7.599099999999997], ["119", 0.21800000000000003], ["148", 0.12639999999999998], ["178", 0.046], ["208", 0.057499999999999996], ["237", 0.046], ["267", 0.023], ["296", 0.0345], ["326", 0.0115], ["356", 0.0115], ["385", 0.0115], ["415", 0.0115], ["445", 0.33270...
{"lang": "python3", "distribution": [["19000", 0.0115], ["19200", 0.0115], ["19300", 0.0688], ["19400", 0.0458], ["19500", 0.0573], ["19600", 0.2292], ["19700", 0.2292], ["19800", 4.0], ["19900", 19.4384], ["20000", 5.5817], ["20100", 19.0831], ["20200", 43.6562]]}
[ { "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n self.nums = nums\n self.cur_sums = [0]\n for i in range(len(nums)):\n self.cur_sums.append(nums[i] + self.cur_sums[-1])\n \n\n def sumRange(self, left: int, right: int) -> int:\n return self...
112
[ { "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n self.nums=nums\n \n\n def sumRange(self, left: int, right: int) -> int:\n summation=0\n while left<=right:\n summation+=self.nums[left]\n left+=1\n return summation\n\n\n# Your Nu...
17
304
range-sum-query-2d-immutable
<p>Given a 2D matrix <code>matrix</code>, handle multiple queries of the following type:</p> <ul> <li>Calculate the <strong>sum</strong> of the elements of <code>matrix</code> inside the rectangle defined by its <strong>upper left corner</strong> <code>(row1, col1)</code> and <strong>lower right corner</strong> <code...
55.256135
Medium
[ "array", "design", "matrix", "prefix-sum" ]
{"lang": "python3", "distribution": [["950", 0.9972999999999999], ["963", 5.8735], ["975", 13.225000000000001], ["988", 18.396800000000002], ["1001", 19.504900000000003], ["1013", 12.486100000000002], ["1026", 5.873599999999999], ["1039", 3.5096], ["1051", 2.475], ["1064", 0.9234], ["1077", 0.9604999999999999], ["1089"...
{"lang": "python3", "distribution": [["25700", 0.0369], ["25900", 0.0739], ["26000", 0.0739], ["26100", 0.0739], ["26200", 0.0369], ["26300", 0.0369], ["26400", 0.0739], ["26500", 0.1108], ["26600", 0.0369], ["26700", 0.1478], ["26800", 0.9235], ["26900", 3.805], ["27000", 4.7654], ["27100", 6.6864], ["27200", 11.7843]...
[ { "code": "from itertools import accumulate\n\nclass NumMatrix:\n\n def __init__(self, matrix: List[List[int]]):\n W = len(matrix[0])\n self._s = [None]*len(matrix)\n\n for y, row in enumerate(matrix):\n s = 0\n sum_row = list(accumulate(row))\n if y>0:\n...
116
[ { "code": "class NumMatrix:\n def __init__(self, matrix: List[List[int]]):\n ROWS, COLS = len(matrix)+1, len(matrix[0])+1\n self.prefix_sum = [[0] * COLS for _ in range(ROWS)]\n for r in range(1, ROWS):\n col_sum = 0\n for c in range(1, COLS):\n col_s...
41
307
range-sum-query-mutable
<p>Given an integer array <code>nums</code>, handle multiple queries of the following types:</p> <ol> <li><strong>Update</strong> the value of an element in <code>nums</code>.</li> <li>Calculate the <strong>sum</strong> of the elements of <code>nums</code> between indices <code>left</code> and <code>right</code> <st...
41.273426
Medium
[ "array", "design", "binary-indexed-tree", "segment-tree" ]
{"lang": "python3", "distribution": [["801", 0.42000000000000004], ["821", 0.07], ["841", 0.07], ["862", 0.07], ["882", 0.07], ["902", 0.07], ["923", 0.07], ["943", 0.6301000000000001], ["964", 1.2604000000000002], ["984", 1.1204000000000003], ["1004", 0.49000000000000005], ["1025", 1.4006], ["1045", 2.9411999999999994...
{"lang": "python3", "distribution": [["32505", 0.2801], ["32715", 0.4202], ["32925", 2.3809], ["33135", 1.4005], ["33345", 1.9607], ["33555", 3.1513], ["33765", 7.423], ["33975", 9.7339], ["34185", 7.212899999999999], ["34395", 13.4454], ["34605", 3.7815], ["34815", 0.4902], ["35025", 1.6107], ["35235", 1.2605], ["3544...
[ { "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n self.nums = nums\n self.sum = sum(nums)\n self.hashmap = {}\n\n def update(self, index: int, val: int) -> None:\n self.sum += val - self.nums[index]\n self.nums[index] = val\n self.hashmap = {}\...
147
[ { "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n self.data = nums\n n = len(nums)\n self.tree = [0] * (n + 1)\n for i in range(n):\n self.tree[i + 1] = nums[i]\n for i in range(1, len(self.tree)):\n j = i + (i & -i)\n if...
89
162
find-peak-element
<p>A peak element is an element that is strictly greater than its neighbors.</p> <p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p> <p>You may imagine that <c...
46.014289
Medium
[ "array", "binary-search" ]
{"lang": "python3", "distribution": [["24", 0.0048], ["25", 0.0191], ["26", 0.0191], ["27", 0.0191], ["28", 0.0811], ["29", 0.0286], ["30", 0.1289], ["31", 0.1146], ["32", 0.3055], ["33", 0.3437], ["34", 0.673], ["35", 0.5728], ["36", 1.3079], ["37", 1.5609], ["38", 2.148], ["39", 1.8425], ["40", 3.7088], ["41", 4.3389...
{"lang": "python3", "distribution": [["16000", 0.0048], ["16200", 0.0048], ["16300", 0.0334], ["16400", 0.6014], ["16500", 9.1122], ["16600", 27.4129], ["16700", 45.1504]]}
[ { "code": "class Solution:\n def findPeakElement(self, nums: List[int]) -> int:\n n = len(nums)\n if n == 1:\n return 0\n if nums[0] > nums[1]:\n return 0\n if nums[n-1] > nums[n-2]:\n return n-1\n low = 1\n high = n-2\n while ...
52
[ { "code": "class Solution:\n def findPeakElement(self, nums: List[int]) -> int:\n l = 0\n r = len(nums) - 1\n while l < r:\n mid = (l + r) // 2\n # \"\\\" slope\n if nums[mid] > nums[mid+1]:\n r = mid\n else:\n # \...
11
164
maximum-gap
<p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p> <p>You must write an algorithm that runs in linear time and uses linear extra space.</p> <p>&nbsp;</p> <p><st...
47.226242
Medium
[ "array", "sorting", "bucket-sort", "radix-sort" ]
{"lang": "python3", "distribution": [["654", 0.20400000000000001], ["664", 0.1632], ["674", 0.3264], ["684", 0.36710000000000004], ["694", 0.6117], ["704", 2.243], ["714", 4.7307999999999995], ["724", 6.035799999999999], ["734", 7.504099999999999], ["744", 6.77], ["754", 6.484399999999999], ["764", 7.5855999999999995],...
{"lang": "python3", "distribution": [["26903", 0.0816], ["27111", 0.0816], ["27318", 0.5301], ["27526", 0.5302], ["27733", 0.0408], ["27941", 0.0408], ["28148", 0.0408], ["28356", 0.1223], ["28563", 0.2039], ["28771", 0.0408], ["28978", 0.0816], ["29186", 0.2855], ["29393", 0.8972], ["29601", 5.016299999999999], ["2980...
[ { "code": "class Solution:\n def maximumGap(self, l: List[int]) -> int:\n l = sorted(set(l))\n r=0\n for i in range(1,len(l)):\n t=l[i]-l[i-1]\n if t>r:\n r=t\n return r ", "runtime": "654" }, { "code": "class Solution:\n ...
151
[ { "code": "class Solution:\n def maximumGap(self, nums: List[int]) -> int:\n if len(nums) < 2: return 0\n nums.sort()\n for i in range(len(nums)-1):\n nums[i] = abs(nums[i]-nums[i+1])\n nums.pop()\n return max(nums)", "memory": "26903" }, { "code": "c...
130
165
compare-version-numbers
<p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>&#39;.&#39;</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<...
41.337435
Medium
[ "two-pointers", "string" ]
{"lang": "python3", "distribution": [["17", 0.0647], ["18", 0.1295], ["19", 0.2266], ["20", 0.2266], ["21", 0.1942], ["22", 0.8417], ["23", 0.6151], ["24", 0.9064], ["25", 0.8417], ["26", 2.2985], ["27", 2.4927], ["28", 2.6222], ["29", 3.1725], ["30", 5.9566], ["31", 4.4027], ["32", 4.2732], ["33", 7.1544], ["34", 10.0...
{"lang": "python3", "distribution": [["16200", 0.1619], ["16300", 3.6581], ["16400", 23.1466], ["16500", 38.3296]]}
[ { "code": "class Solution:\n def compareVersion(self, version1: str, version2: str) -> int:\n arr1=version1.split(\".\") \n arr2=version2.split(\".\")\n i=0\n while i<max(len(arr1),len(arr2)):\n if i >= len(arr1):\n ver1=0\n else:\n ...
41
[ { "code": "class Solution:\n def compareVersion(self, version1: str, version2: str) -> int:\n nums1 = version1.split(\".\")\n nums2 = version2.split(\".\")\n n1, n2 = len(nums1), len(nums2)\n\n for i in range(max(n1, n2)):\n i1 = int(nums1[i]) if i < n1 else 0\n ...
4
166
fraction-to-recurring-decimal
<p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p> <p>If the fractional part is repeating, enclose the repeating part in parentheses.</p> <p>If multiple answers are possible, return <strong>any of them</strong>.<...
25.37668
Medium
[ "hash-table", "math", "string" ]
{"lang": "python3", "distribution": [["14", 0.0776], ["18", 0.0776], ["19", 0.0776], ["20", 0.0776], ["21", 0.3103], ["22", 0.1552], ["23", 0.4655], ["24", 0.7758], ["25", 1.0861], ["26", 2.948], ["27", 1.5516], ["28", 2.2498], ["29", 3.4911], ["30", 5.896], ["31", 4.1117], ["32", 3.5687], ["33", 6.3615], ["34", 9.6199...
{"lang": "python3", "distribution": [["16300", 0.1552], ["16400", 0.1552], ["16500", 1.8619], ["16600", 13.7316], ["16700", 28.3165], ["16800", 36.3848]]}
[ { "code": "class Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:\n if numerator == 0:\n return \"0\"\n \n fraction = []\n if (numerator < 0) != (denominator < 0):\n fraction.append(\"-\")\n \n dividend = abs(num...
39
[ { "code": "class Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:\n if numerator % denominator == 0:\n return str(numerator // denominator)\n \n sign = '-' if (numerator < 0) != (denominator < 0) else ''\n numerator, denominator = abs(nu...
10
167
two-sum-ii-input-array-is-sorted
<p>Given a <strong>1-indexed</strong> array of integers <code>numbers</code> that is already <strong><em>sorted in non-decreasing order</em></strong>, find two numbers such that they add up to a specific <code>target</code> number. Let these two numbers be <code>numbers[index<sub>1</sub>]</code> and <code>numbers[index...
62.084327
Medium
[ "array", "two-pointers", "binary-search" ]
{"lang": "python3", "distribution": [["23", 0.0048], ["25", 0.0071], ["26", 0.0048], ["28", 0.0118], ["29", 0.0071], ["31", 0.0095], ["32", 0.0118], ["34", 0.0071], ["35", 0.0237], ["37", 0.0095], ["38", 0.011800000000000001], ["40", 0.0095], ["41", 0.0166], ["43", 0.0047], ["44", 0.0024], ["46", 0.0024], ["47", 0.0048...
{"lang": "python3", "distribution": [["16300", 0.0047], ["16400", 0.0166], ["16500", 0.0355], ["16600", 0.0687], ["16700", 0.0071], ["16800", 0.0047], ["16900", 0.0332], ["17000", 0.0166], ["17100", 0.0213], ["17200", 0.0971], ["17300", 1.2108], ["17400", 3.0069], ["17500", 1.0994], ["17600", 4.8053], ["17700", 48.9302...
[ { "code": "class Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n f = open(\"user.out\", 'w')\n print(\"[1,2]\", file=f)\n print(\"[1,3]\", file=f)\n print(\"[1,2]\", file=f)\n print(\"[1,2]\", file=f)\n print(\"[1,2]\", file=f)\n ...
120
[ { "code": "# this is just a test. credit goes to the sample submissions in the \"Submissions\" tab\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n f = open(\"user.out\", 'w')\n print(\"[1,2]\", file=f)\n print(\"[1,3]\", file=f)\n print(\"[1,2]...
20
168
excel-sheet-column-title
<p>Given an integer <code>columnNumber</code>, return <em>its corresponding column title as it appears in an Excel sheet</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong...
41.629838
Easy
[ "math", "string" ]
{"lang": "python3", "distribution": [["11", 0.0253], ["12", 0.0253], ["15", 0.0505], ["16", 0.0253], ["18", 0.1263], ["19", 0.0758], ["20", 0.5053], ["21", 0.2274], ["22", 0.5811], ["23", 0.6316], ["24", 1.4149], ["25", 1.0359], ["26", 2.4507], ["27", 1.9202], ["28", 3.9161], ["29", 3.8909], ["30", 5.2299], ["31", 3.61...
{"lang": "python3", "distribution": [["16200", 0.1011], ["16300", 3.1329], ["16400", 19.9343], ["16500", 37.3674]]}
[ { "code": "class Solution:\n def convertToTitle(self, columnNumber: int) -> str:\n al = list(string.ascii_uppercase)\n temp = []\n \n while columnNumber > 0:\n columnNumber = columnNumber - 1\n print(\"col is\", columnNumber)\n temp.append(al[(colu...
44
[ { "code": "class Solution:\n def convertToTitle(self, cnumber: int) -> str:\n result = []\n \n while cnumber > 0:\n cnumber -= 1 \n remainder = cnumber % 26\n result.append(chr(remainder + ord('A')))\n cnumber //= 26\n \n return ...
6
169
majority-element
<p>Given an array <code>nums</code> of size <code>n</code>, return <em>the majority element</em>.</p> <p>The majority element is the element that appears more than <code>&lfloor;n / 2&rfloor;</code> times. You may assume that the majority element always exists in the array.</p> <p>&nbsp;</p> <p><strong class="example...
65.208023
Easy
[ "array", "hash-table", "divide-and-conquer", "sorting", "counting" ]
{"lang": "python3", "distribution": [["34", 0.0017], ["36", 0.0017], ["38", 0.0052], ["39", 0.0017], ["40", 0.0035], ["41", 0.0017], ["42", 0.0035], ["44", 0.007], ["45", 0.0052], ["46", 0.0122], ["47", 0.0052], ["48", 0.0052], ["49", 0.0104], ["50", 0.0017], ["51", 0.007], ["52", 0.0052], ["53", 0.0035], ["54", 0.007]...
{"lang": "python3", "distribution": [["16500", 0.0017], ["16700", 0.0017], ["17000", 0.0035], ["17100", 0.0087], ["17200", 0.0087], ["17300", 0.007], ["17400", 0.0261], ["17500", 0.0244], ["17600", 0.0748], ["17700", 0.1479], ["17800", 1.1533], ["17900", 18.7994], ["18000", 58.8578]]}
[ { "code": "f = open(\"user.out\", 'w')\nfor line in stdin:\n l = sorted(map(int, line.rstrip()[1:-1].split(',')))\n print(l[len(l) // 2], file=f)", "runtime": "34" }, { "code": "\nf = open(\"user.out\", 'w')\nfor line in stdin:\n l = sorted(map(int, line.rstrip()[1:-1].split(',')))\n pri...
113
[ { "code": "class Solution:\n def majorityElement(self, nums: List[int]) -> int:\n count = defaultdict(int)\n max = nums[0]\n for i in nums:\n count[i] += 1\n if count[i] > count[max]:\n max = i\n return max\n\n \n ", "memory": "17...
18
41
first-missing-positive
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
39.958925
Hard
[ "array", "hash-table" ]
{"lang": "python3", "distribution": [["64", 0.0545], ["68", 0.0327], ["73", 0.0761], ["77", 0.0327], ["82", 0.0218], ["87", 0.0218], ["91", 0.0109], ["96", 0.0218], ["100", 0.0109], ["105", 0.0109], ["109", 0.0109], ["114", 0.0109], ["118", 0.0109], ["123", 0.0218], ["127", 0.0109], ["132", 0.0109], ["137", 0.0109], ["...
{"lang": "python3", "distribution": [["23488", 0.0544], ["23666", 0.0326], ["23843", 0.0109], ["24021", 0.0218], ["24198", 0.087], ["24376", 0.1523], ["24553", 0.0979], ["24731", 0.1631], ["24908", 0.0761], ["25086", 0.0653], ["25263", 0.2067], ["25441", 0.7831], ["25618", 0.3698], ["25796", 0.0544], ["25973", 0.0109],...
[ { "code": "class Solution:\n def firstMissingPositive(self, nums: List[int]) -> int:\n nums=set(nums)\n ans=1\n while ans in nums:\n ans+=1\n return ans\n\n\nwith open(\"user.out\", \"w\") as f:\n inputs = map(loads, stdin)\n for nums in inputs:\n print(Sol...
123
[ { "code": "from typing import List\nfrom bisect import bisect_left\nfrom sys import stdin\nfrom json import loads\n\ndef firstMissingPositive(nums: List[int]) -> int:\n nums = sorted([N for N in nums if 0 < N])\n I, L = 1, len(nums)\n while True:\n current = bisect_left(nums, I)\n if curr...
110
42
trapping-rain-water
<p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s...
63.094684
Hard
[ "array", "two-pointers", "dynamic-programming", "stack", "monotonic-stack" ]
{"lang": "python3", "distribution": [["31", 0.0087], ["33", 0.0029], ["34", 0.0029], ["36", 0.0058], ["38", 0.0058], ["39", 0.0058], ["41", 0.0087], ["42", 0.0203], ["44", 0.0174], ["45", 0.0029], ["47", 0.0058], ["48", 0.0174], ["50", 0.0087], ["52", 0.0029], ["53", 0.0116], ["55", 0.0087], ["56", 0.0116], ["58", 0.01...
{"lang": "python3", "distribution": [["17400", 0.0029], ["17500", 0.0058], ["17600", 0.0058], ["17700", 0.0753], ["17800", 0.1187], ["17900", 0.0145], ["18000", 0.0319], ["18100", 0.11], ["18200", 1.1294], ["18300", 16.7468], ["18400", 38.8104], ["18500", 15.2207], ["18600", 15.962], ["18700", 4.7956], ["18800", 1.9315...
[ { "code": "class Solution:\n def trap(height: List[int]) -> int:\n n = len(height)\n i, j = 0, n - 1\n leftMax, rightMax = height[i], height[j]\n\n res = 0\n\n while i < j:\n if leftMax < rightMax:\n res += leftMax - height[i]\n i +=...
124
[ { "code": "class Solution:\n def trap(self, height: List[int]) -> int:\n ans = 0\n l, r = 0, len(height)-1\n lMax, rMax = height[l], height[r]\n\n while l < r:\n if height[l] <= height[r]:\n if height[l] < lMax:\n ans += (lMax - height[...
23
43
multiply-strings
<p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p> <p><strong>Note:</strong>&nbsp;You must not use any built-in BigInteger library or convert the inputs to integer directly.<...
40.959953
Medium
[ "math", "string", "simulation" ]
{"lang": "python3", "distribution": [["13", 0.0312], ["15", 0.0416], ["17", 0.0312], ["18", 0.052], ["20", 0.1248], ["22", 0.7589], ["24", 0.3015], ["25", 2.1312], ["27", 1.5386000000000002], ["29", 4.907], ["30", 1.7881], ["32", 6.5287], ["34", 7.173299999999999], ["36", 2.9109], ["37", 8.3065], ["39", 5.905], ["41", ...
{"lang": "python3", "distribution": [["16000", 0.0208], ["16100", 0.0208], ["16200", 0.1871], ["16300", 3.1604], ["16400", 14.7936], ["16500", 31.2506], ["16600", 29.868], ["16700", 14.804]]}
[ { "code": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:\n a=str(int(num1)*int(num2))\n return a", "runtime": "13" }, { "code": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:\n k=int(num1)\n s=int(num2)\n return str(k...
137
[ { "code": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:\n res = 0\n n1,n2 = len(num1)-1, len(num2)-1\n for i in range(n1, -1, -1):\n for j in range(n2, -1, -1):\n product = int(num1[i]) * int(num2[j])\n product *= (10**(n1 - ...
14
44
wildcard-matching
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
28.6085
Hard
[ "string", "dynamic-programming", "greedy", "recursion" ]
{"lang": "python3", "distribution": [["32", 5.908300000000001], ["48", 10.864299999999998], ["64", 0.3172], ["80", 0.21960000000000002], ["96", 0.36600000000000005], ["112", 0.3172], ["128", 0.1464], ["144", 0.0976], ["160", 0.122], ["176", 0.1464], ["192", 0.2684], ["209", 0.7564000000000002], ["225", 0.82979999999999...
{"lang": "python3", "distribution": [["17001", 25.585799999999992], ["18805", 0.5125], ["20609", 0.9521999999999999], ["22413", 0.0488], ["24216", 31.884699999999995], ["26020", 8.740399999999998], ["27824", 1.9288], ["29628", 0.2441], ["31431", 0.0976], ["33235", 0.24409999999999998], ["35039", 0.0976], ["36843", 0.19...
[ { "code": "class Solution(object):\n def isMatch(self, string, pattern):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: bool\n \"\"\"\n first, second = 0, 0\n length1, length2 = len(pattern), len(string)\n star_index, match_index = -1, -1\n\n w...
153
[ { "code": "class Solution:\n def isMatch(self, st: str, pattern: str) -> bool:\n s, p, mat, star = 0, 0, 0, -1\n while s < len(st):\n if p < len(pattern) and (pattern[p] == \"?\" or pattern[p] == st[s]):\n s += 1\n p += 1\n elif p < len(patter...
123
45
jump-game-ii
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
40.719079
Medium
[ "array", "dynamic-programming", "greedy" ]
{"lang": "python3", "distribution": [["76", 65.8323], ["152", 2.972200000000002], ["229", 0.30740000000000023], ["306", 0.05599999999999999], ["382", 0.12529999999999997], ["459", 1.8397999999999999], ["535", 0.9327000000000002], ["612", 1.0148000000000004], ["688", 0.48110000000000014], ["765", 0.42910000000000026], [...
{"lang": "python3", "distribution": [["16600", 0.0043], ["16700", 0.0043], ["16900", 0.013], ["17000", 0.0174], ["17100", 0.0651], ["17200", 0.3254], ["17300", 0.4512], ["17400", 3.0458], ["17500", 18.852], ["17600", 35.6734], ["17700", 26.4318], ["17800", 5.3237], ["17900", 1.0977], ["18000", 0.3081], ["18100", 0.269]...
[ { "code": "class Solution:\n def jump(nums: List[int]) -> int:\n total = 0\n jump = 0\n max_dis = 0\n lenn=len(nums)\n if lenn==1:\n return 0\n for i, num in enumerate(nums):\n if i+num>max_dis:\n max_dis=i+num\n if i+n...
150
[ { "code": "class Solution:\n \n \n \n def jump(self, nums: List[int]) -> int:\n \n \n queue=deque([])\n queue.append((0,0))\n if len(nums)==1:\n return 0\n visited=[False]*len(nums)\n while(queue):\n \n temp,dist=queue.pop...
52
46
permutations
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
79.229867
Medium
[ "array", "backtracking" ]
{"lang": "python3", "distribution": [["17", 0.0034], ["18", 0.0068], ["19", 0.0205], ["20", 0.0205], ["21", 0.0171], ["22", 0.0443], ["23", 0.0921], ["24", 0.0955], ["25", 0.0887], ["26", 0.307], ["27", 0.6208], ["28", 0.4741], ["29", 0.5594], ["30", 1.1359], ["31", 2.2172], ["32", 1.593], ["33", 2.0228], ["34", 3.5407...
{"lang": "python3", "distribution": [["16100", 0.0102], ["16200", 0.0205], ["16300", 0.0614], ["16400", 0.8323], ["16500", 7.5283], ["16600", 22.8135], ["16700", 36.7888], ["16800", 26.4156]]}
[ { "code": "class Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n res = []\n def dfs(cur):\n if len(nums) == len(cur):\n \n res.append(cur.copy())\n return\n for j in nums:\n if j not in cur:\n...
54
[ { "code": "class Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n res = []\n\n def dfs(tempArray):\n if len(tempArray) == len(nums):\n res.append(tempArray.copy())\n return\n\n for i in range(len(nums)):\n if...
11
47
permutations-ii
<p>Given a collection of numbers, <code>nums</code>,&nbsp;that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,1,2] <strong>Output:</strong> [[1,1,2], ...
60.029355
Medium
[ "array", "backtracking" ]
{"lang": "python3", "distribution": [["32", 0.8037], ["40", 9.7636], ["48", 31.714199999999998], ["56", 21.8423], ["64", 3.8144], ["73", 2.387], ["81", 1.3674], ["89", 0.5997999999999999], ["97", 0.288], ["105", 0.24], ["113", 0.15600000000000003], ["122", 0.10799999999999998], ["130", 0.10799999999999998], ["138", 0.3...
{"lang": "python3", "distribution": [["16300", 0.036], ["16400", 0.108], ["16500", 0.6477], ["16600", 4.642], ["16700", 16.4448], ["16800", 26.3884], ["16900", 24.5412], ["17000", 9.7637], ["17100", 6.825], ["17200", 2.0271], ["17300", 1.4634], ["17400", 0.9596], ["17500", 0.2759], ["17600", 0.1799], ["17700", 0.048], ...
[ { "code": "class Solution:\n def permuteUnique(self, nums: List[int]) -> List[List[int]]:\n # nums.sort()\n def helper(i):\n nonlocal nums\n if i >= len(nums):\n return [[]]\n currPerms = set()\n nextPerms = helper(i+1)\n for...
155
[ { "code": "# O(N * !N) T and O(N * !N) S recursive backtracking solution (NeetCode's modded)\nclass Solution:\n def permuteUnique(self, nums: List[int]) -> List[List[int]]:\n res = []\n N = len(nums)\n numToCount = {}\n for n in nums:\n numToCount[n] = numToCount.get(n,...
34
48
rotate-image
<p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p> <p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ...
75.869651
Medium
[ "array", "math", "matrix" ]
{"lang": "python3", "distribution": [["15", 0.0077], ["16", 0.0077], ["17", 0.0038], ["18", 0.0154], ["19", 0.0307], ["20", 0.0615], ["21", 0.0499], ["22", 0.1306], ["23", 0.1114], ["24", 0.2727], ["25", 0.2343], ["26", 0.7336], ["27", 0.6222], ["28", 1.5057], ["29", 1.2598], ["30", 2.1894], ["31", 1.6555], ["32", 4.15...
{"lang": "python3", "distribution": [["15800", 0.0038], ["16100", 0.0192], ["16200", 0.0461], ["16300", 0.6606], ["16400", 12.1798], ["16500", 40.941], ["16600", 37.9028]]}
[ { "code": "class Solution:\n def rotate(self, matrix: list[list[int]]) -> None:\n n = len(matrix)\n\n for offset in range(n//2):\n for ind in range(offset, n-offset-1):\n val1 = matrix[offset][ind]\n val2 = matrix[ind][n-offset-1]\n val3 =...
53
[ { "code": "class Solution:\n def rotate(self, matrix: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify matrix in-place instead.\n \"\"\"\n n = len(matrix)\n m = len(matrix[0])\n\n for i in range(n):\n for j in range(m):\n ...
11
49
group-anagrams
<p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</strong> <span class="example-io"...
69.393195
Medium
[ "array", "hash-table", "string", "sorting" ]
{"lang": "python3", "distribution": [["42", 0.007299999999999999], ["43", 0.0074], ["44", 0.0018], ["45", 0.0055], ["47", 0.0111], ["48", 0.0055], ["49", 0.0074], ["50", 0.0018], ["51", 0.0092], ["52", 0.0037], ["53", 0.0055], ["54", 0.0055], ["55", 0.0037], ["57", 0.0018], ["58", 0.0037], ["59", 0.0074], ["60", 0.0111...
{"lang": "python3", "distribution": [["18200", 0.0037], ["18300", 0.0074], ["18400", 0.0074], ["18500", 0.0111], ["18600", 0.0055], ["18700", 0.0092], ["18800", 0.0018], ["18900", 0.0129], ["19000", 0.0296], ["19100", 0.0684], ["19200", 0.3607], ["19300", 4.4355], ["19400", 6.9751], ["19500", 2.0901], ["19600", 10.2064...
[ { "code": "f = open('user.out', 'w')\nfor strs in map(loads, stdin):\n w = defaultdict(list)\n for s in strs:\n w[''.join(sorted(s))].append(s)\n print(str(w.values())[12:-1].replace(\"'\", '\"').replace(\" \", \"\"), file=f)\nexit()\n", "runtime": "42" }, { "code": "# class Solution...
131
[ { "code": "class Solution:\n def groupAnagrams(self, strs: List[str]) -> List[List[str]]:\n found_anagrams={}\n anagrams_groups =[]\n for i, str in enumerate(strs):\n str_hashmap= {}\n str_group=[]\n str_group.append(str)\n if str not in found_...
72
50
powx-n
<p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> x = 2.00000, ...
35.534516
Medium
[ "math", "recursion" ]
{"lang": "python3", "distribution": [["13", 0.0042], ["14", 0.0042], ["15", 0.0378], ["16", 0.0168], ["17", 0.0252], ["18", 0.0504], ["19", 0.2522], ["20", 0.1135], ["21", 0.1933], ["22", 0.5758], ["23", 0.8363], ["24", 0.5169], ["25", 0.9372], ["26", 2.3199], ["27", 2.4628], ["28", 1.7357], ["29", 2.7486], ["30", 6.23...
{"lang": "python3", "distribution": [["16100", 0.0336], ["16200", 0.2017], ["16300", 2.8116], ["16400", 12.0493], ["16500", 33.8615], ["16600", 36.3579]]}
[ { "code": "class Solution:\n def myPow(self, x: float, n: int) -> float:\n if n == 0:return 1\n if n < 0:return self.myPow(1/x, -n)\n lower = self.myPow(x, n//2)\n if n % 2 == 0:return lower * lower\n else: return lower * lower * x", "runtime": "13" }, { "code":...
50
[ { "code": "class Solution:\n def myPow(self, x: float, n: int) -> float:\n return x**n", "memory": "16100" }, { "code": "class Solution:\n myPow = lambda self, x, n: x**n\n ", "memory": "16200" }, { "code": "class Solution:\n def myPow(self, x: float, n: int) -> fl...
10
217
contains-duplicate
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
62.227883
Easy
[ "array", "hash-table", "sorting" ]
{"lang": "python3", "distribution": [["21", 0.0050999999999999995], ["27", 0.0234], ["32", 0.024900000000000002], ["38", 0.0216], ["44", 0.0067], ["49", 0.0017], ["55", 0.0034], ["60", 0.0167], ["66", 0.0067], ["71", 0.0084], ["77", 0.0034], ["82", 0.0017], ["88", 0.0017], ["94", 0.0017], ["99", 0.0017], ["105", 0.0017...
{"lang": "python3", "distribution": [["16300", 0.0033], ["16400", 0.0182], ["16500", 0.0297], ["16600", 0.0248], ["24000", 0.0017], ["24100", 0.0033], ["26600", 0.0017], ["26700", 0.0033], ["26800", 0.0017], ["27100", 0.0017], ["27300", 0.0033], ["27400", 0.0033], ["27500", 0.0066], ["27600", 0.0248], ["27700", 0.0347]...
[ { "code": "f = open('user.out', 'w')\nprint('''true\nfalse\ntrue\nfalse\nfalse\ntrue\nfalse\nfalse\ntrue\ntrue\ntrue\nfalse\ntrue\ntrue\ntrue\ntrue\ntrue\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\nfalse\nfalse\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\nfalse\ntrue\nfalse\ntrue\nfalse\nt...
138
[ { "code": "f = open('user.out', 'w')\nprint('''true\nfalse\ntrue\nfalse\nfalse\ntrue\nfalse\nfalse\ntrue\ntrue\ntrue\nfalse\ntrue\ntrue\ntrue\ntrue\ntrue\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\nfalse\nfalse\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\ntrue\nfalse\nfalse\nfalse\nfalse\ntrue\nfalse\ntrue\nfalse\nt...
96
218
the-skyline-problem
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
43.058071
Hard
[ "array", "divide-and-conquer", "binary-indexed-tree", "segment-tree", "line-sweep", "heap-priority-queue", "ordered-set" ]
{"lang": "python3", "distribution": [["105", 76.8974], ["161", 1.8645999999999998], ["217", 0.4662], ["274", 0.7326], ["330", 0.1332], ["386", 0.1332], ["443", 0.19980000000000003], ["499", 0.5328], ["555", 0.333], ["612", 0.1332], ["668", 0.0666], ["725", 0.0666], ["781", 0.1332], ["837", 0.1332], ["894", 0.1998000000...
{"lang": "python3", "distribution": [["21000", 0.0666], ["21100", 0.0666], ["21200", 0.1997], ["21300", 3.2623], ["21400", 5.6591], ["21500", 1.6644], ["21600", 2.6631], ["21700", 7.5233], ["21800", 10.3196], ["21900", 9.3209], ["22000", 8.2557], ["22100", 6.2583], ["22200", 3.2623], ["22300", 2.7963], ["22400", 2.3968...
[ { "code": "from typing import List\nfrom bisect import bisect_left, bisect_right\n\nclass Solution:\n def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:\n # If there are no buildings, return an empty list\n if len(buildings) == 0:\n return []\n \n # So...
104
[ { "code": "class Solution:\n def getSkyline(self, buildings: list[list[int]]) -> list[list[int]]:\n n = len(buildings)\n if n == 0:\n return []\n if n == 1:\n left, right, height = buildings[0]\n return [[left, height], [right, 0]]\n\n left = self.getSkyline(buildings[:n // 2])\n ...
37
219
contains-duplicate-ii
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
46.437366
Easy
[ "array", "hash-table", "sliding-window" ]
{"lang": "python3", "distribution": [["66", 0.015], ["72", 0.0347], ["78", 0.0398], ["84", 0.0199], ["90", 0.005], ["96", 0.0099], ["102", 0.005], ["108", 0.0099], ["114", 0.0099], ["120", 0.0199], ["126", 0.0249], ["132", 0.0199], ["138", 0.0199], ["144", 0.0547], ["150", 0.0398], ["156", 0.1243], ["162", 0.0796], ["1...
{"lang": "python3", "distribution": [["24763", 0.01], ["24891", 0.005], ["25018", 0.0099], ["25146", 0.005], ["25273", 0.005], ["25401", 0.005], ["25528", 0.0099], ["25656", 0.005], ["25783", 0.005], ["25911", 0.005], ["26038", 0.005], ["26166", 0.0099], ["26293", 0.0149], ["26421", 0.0199], ["26548", 0.0448], ["26676"...
[ { "code": "def check(arr,k):\n dic = {}\n for i in range(len(arr)):\n if arr[i] in dic and abs(dic[arr[i]]-i) <= k:\n return \"true\"\n else:\n dic[arr[i]] = i \n return 'false'\n\n\nif __name__=='__main__':\n f = open('user.out','w')\n data = list(map(loads,st...
135
[ { "code": "class Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:\n arr = []\n\n for idx, num in enumerate(nums):\n if num in arr: return True\n arr.append(num)\n if len(arr) > k: arr.pop(0)\n\n return False\n \n\...
107
220
contains-duplicate-iii
<p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p> <p>Find a pair of indices <code>(i, j)</code> such that:</p> <ul> <li><code>i != j</code>,</li> <li><code>abs(i - j) &lt;= indexDiff</code>.</li> <li><code>abs(nums[i] - nums[j]) &lt;= valueD...
22.990625
Hard
[ "array", "sliding-window", "sorting", "bucket-sort", "ordered-set" ]
{"lang": "python3", "distribution": [["705", 1.2975999999999999], ["745", 10.948499999999997], ["785", 13.543699999999998], ["825", 7.785599999999999], ["864", 12.002799999999995], ["904", 5.758100000000004], ["944", 1.3786999999999996], ["984", 0.8109999999999999], ["1023", 0.3244], ["1063", 0.8109999999999999], ["110...
{"lang": "python3", "distribution": [["28101", 0.1622], ["28305", 0.2433], ["28509", 0.2433], ["28713", 0.0811], ["28916", 0.9732], ["29120", 9.8135], ["29324", 20.5191], ["29528", 2.5953], ["29731", 0.5677], ["29935", 0.3244], ["30139", 0.4866], ["30343", 0.6488], ["30546", 0.7299], ["30750", 0.4866], ["30954", 0.7299...
[ { "code": "class Solution:\n def containsNearbyAlmostDuplicate(self, nums: List[int], k: int, t: int) -> bool:\n buckets = {}\n if t == 0:\n for index, num in enumerate(nums):\n if num in buckets and index - buckets[num] <= k:\n return True \n ...
85
[ { "code": "from sortedcontainers import SortedList\n\nclass Solution:\n def containsNearbyAlmostDuplicate(self, nums: List[int], indexDiff: int, valueDiff: int) -> bool:\n set_ = SortedList()\n for i in range(len(nums)):\n # Find the successor of current element\n idx = se...
90
221
maximal-square
<p>Given an <code>m x n</code> binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, <em>find the largest square containing only</em> <code>1</code>&#39;s <em>and return its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.l...
47.297006
Medium
[ "array", "dynamic-programming", "matrix" ]
{"lang": "python3", "distribution": [["60", 0.0745], ["78", 0.0149], ["95", 0.0149], ["113", 0.0149], ["131", 0.0297], ["148", 0.0297], ["166", 0.0149], ["183", 0.0297], ["201", 0.0297], ["218", 0.0149], ["236", 0.0149], ["254", 0.0149], ["271", 0.0149], ["289", 0.0149], ["306", 0.0297], ["324", 0.0149], ["341", 0.0149...
{"lang": "python3", "distribution": [["18475", 0.1785], ["19025", 14.183699999999998], ["19575", 59.664], ["20125", 2.5871], ["20675", 0.9069], ["21225", 1.576], ["21775", 1.8136999999999999], ["22325", 0.5353], ["22875", 0.37170000000000003], ["23425", 0.0595], ["23975", 0.0149], ["24525", 0.5353], ["25075", 0.9367000...
[ { "code": "\ndef maximalSquare(matrix):\n bits = [int(''.join(row), 2) for row in matrix]\n w = 0\n while bits and any(bits):\n w += 1\n bits = [a & b for a, b in itertools.pairwise(b & (b << 1) for b in bits)]\n return w * w\nwith open('user.out', 'w') as f:\n for case in map(loads...
122
[ { "code": "\ndef maximalSquare(bits):\n w = 0\n while bits and any(bits):\n w += 1\n bits = [a & b for a, b in pairwise(b & (b << 1) for b in bits)]\n return w * w\nwith open('user.out', 'w') as f:\n for case in map(loads, stdin):\n bits = [int(''.join(row), 2) for row in case]\...
114
222
count-complete-tree-nodes
<p>Given the <code>root</code> of a <strong>complete</strong> binary tree, return the number of the nodes in the tree.</p> <p>According to <strong><a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">Wikipedia</a></strong>, every level, except possibly the last, is completely filled...
67.196465
Easy
[ "binary-search", "bit-manipulation", "tree", "binary-tree" ]
{"lang": "python3", "distribution": [["22", 0.0115], ["30", 0.0229], ["31", 0.0459], ["32", 0.0344], ["34", 0.0574], ["35", 0.1262], ["36", 0.0688], ["37", 0.1032], ["38", 0.1721], ["39", 0.2868], ["40", 0.2753], ["41", 0.2638], ["42", 0.5391], ["43", 0.9406], ["44", 1.0209], ["45", 1.2847], ["46", 1.537], ["47", 2.259...
{"lang": "python3", "distribution": [["16900", 0.0229], ["17000", 0.0803], ["17100", 0.0115], ["17200", 0.0229], ["17300", 0.0688], ["21100", 0.0115], ["21200", 0.0344], ["21300", 0.0344], ["21400", 0.1147], ["21500", 1.7206], ["21600", 21.8513], ["21700", 56.6988], ["21800", 13.5811]]}
[ { "code": "import sys\n\nwith open('user.out', 'w') as f:\n while True:\n line = sys.stdin.readline().strip()\n print(line)\n if not line:\n break\n print(line)\n if len(line.split(\",\"))!=1:\n f.write(f'{len(line.split(\",\"))}\\n')\n else:\n ...
62
[ { "code": "import sys\n\nwith open('user.out', 'w') as f:\n while True:\n line = sys.stdin.readline().strip()\n print(line)\n if not line:\n break\n print(line)\n if len(line.split(\",\"))!=1:\n f.write(f'{len(line.split(\",\"))}\\n')\n else:\n ...
20
223
rectangle-area
<p>Given the coordinates of two <strong>rectilinear</strong> rectangles in a 2D plane, return <em>the total area covered by the two rectangles</em>.</p> <p>The first rectangle is defined by its <strong>bottom-left</strong> corner <code>(ax1, ay1)</code> and its <strong>top-right</strong> corner <code>(ax2, ay2)</code>...
46.635076
Medium
[ "math", "geometry" ]
{"lang": "python3", "distribution": [["24", 0.0742], ["28", 0.0742], ["30", 0.0742], ["31", 0.2226], ["32", 0.2967], ["33", 0.2226], ["34", 0.7418], ["35", 0.4451], ["36", 0.7418], ["37", 0.7418], ["38", 1.8546], ["39", 2.3739], ["40", 1.1869], ["41", 2.003], ["42", 4.1543], ["43", 3.7092], ["44", 2.3739], ["45", 3.857...
{"lang": "python3", "distribution": [["16100", 0.0742], ["16300", 0.1484], ["16400", 1.0386], ["16500", 17.5074], ["16600", 44.2878]]}
[ { "code": "class Solution:\n def computeArea(self,\n ax1: int, ay1: int,\n ax2: int, ay2: int,\n bx1: int, by1: int,\n bx2: int, by2: int) -> int:\n area1 = (ax2-ax1)*(ay2-ay1)\n area2 = (bx2-bx1)*(by2-by1)\n\n o...
35
[ { "code": "class Solution:\n def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:\n area_a = (ax2 - ax1) * (ay2 - ay1)\n area_b = (bx2 - bx1) * (by2 - by1)\n \n # check overlap\n overlap = 0\n overlap_x1 = max(...
7
224
basic-calculator
<p>Given a string <code>s</code> representing a valid expression, implement a basic calculator to evaluate it, and return <em>the result of the evaluation</em>.</p> <p><strong>Note:</strong> You are <strong>not</strong> allowed to use any built-in function which evaluates strings as mathematical expressions, such as <...
43.923772
Hard
[ "math", "string", "stack", "recursion" ]
{"lang": "python3", "distribution": [["36", 0.22200000000000003], ["44", 4.7765], ["53", 18.8161], ["61", 21.4431], ["70", 12.7261], ["78", 11.054300000000001], ["87", 7.9323999999999995], ["96", 5.3566], ["104", 2.9682], ["113", 2.3712], ["121", 1.1769999999999998], ["130", 0.9383000000000001], ["138", 0.7507000000000...
{"lang": "python3", "distribution": [["17714", 69.9421], ["18343", 13.851899999999997], ["18971", 2.0812], ["19600", 1.1942], ["20229", 2.7805999999999997], ["20858", 0.7336], ["21486", 0.8359], ["22115", 0.6825000000000001], ["22744", 0.5117999999999999], ["23373", 0.1365], ["24001", 0.15360000000000001], ["24630", 0....
[ { "code": "class Solution:\n def calculate(self, s: str) -> int:\n n = len(s)\n if n == 3894:\n return -56\n if n == 22946:\n return 301\n if n == 211079:\n return -1946\n return eval(s)", "runtime": "36" }, { "code": "class Solu...
98
[ { "code": "parenthesis = {\"(\", \")\"}\noperators = {\"+\", \"-\"}\nnon_digits = parenthesis.union(operators)\n\n\nclass Solution:\n def calculate(self, s: str) -> int:\n s_without_spaces = self.remove_spaces(s)\n stack = []\n\n for char in s_without_spaces:\n if char != \")\...
77
225
implement-stack-using-queues
<p>Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (<code>push</code>, <code>top</code>, <code>pop</code>, and <code>empty</code>).</p> <p>Implement the <code>MyStack</code> class:</p> <ul> <li><code>void push(int x)</code> Pu...
65.204659
Easy
[ "stack", "design", "queue" ]
{"lang": "python3", "distribution": [["13", 0.0129], ["14", 0.0129], ["15", 0.0129], ["16", 0.0773], ["18", 0.0644], ["19", 0.1803], ["20", 0.2962], ["21", 0.2318], ["22", 0.5794], ["23", 0.7597], ["24", 1.1589], ["25", 1.0173], ["26", 2.2534], ["27", 1.8929], ["28", 3.232], ["29", 3.6055], ["30", 6.1808], ["31", 3.747...
{"lang": "python3", "distribution": [["16200", 0.0129], ["16300", 0.2447], ["16400", 4.5841], ["16500", 23.487], ["16600", 40.5099], ["16700", 25.573]]}
[ { "code": "from collections import deque\n\nclass MyStack:\n\n def __init__(self):\n self.q = deque()\n\n def push(self, x: int) -> None:\n self.q.append(x)\n\n def pop(self) -> int:\n print(\"POP\")\n print(self.q)\n self.q.rotate(-1 * (len(self.q) - 1))\n pri...
47
[ { "code": "class MyStack:\n\n def __init__(self):\n self.stack = []\n\n def push(self, x: int) -> None:\n self.stack.append(x)\n\n def pop(self) -> int:\n return self.stack.pop()\n\n def top(self) -> int:\n return self.stack[len(self.stack) - 1]\n\n def empty(self) -> ...
10
226
invert-binary-tree
<p>Given the <code>root</code> of a binary tree, invert the tree, and return <em>its root</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg" style="width: 500px; height: 165px;" /> <pre> <strong>Input:</strong> ro...
77.816121
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["11", 0.0029], ["12", 0.0087], ["15", 0.0349], ["16", 0.0349], ["17", 0.0262], ["18", 0.0699], ["19", 0.198], ["20", 0.1106], ["21", 0.1921], ["22", 0.5153], ["23", 0.6288], ["24", 0.4599], ["25", 0.9286], ["26", 2.4831], ["27", 2.0959], ["28", 1.6273], ["29", 2.879], ["30", 6.0404...
{"lang": "python3", "distribution": [["15900", 0.0029], ["16000", 0.0029], ["16100", 0.0262], ["16200", 0.4105], ["16300", 6.9166], ["16400", 29.0784], ["16500", 48.9724]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom collections import deque\nclass Solution:\n def invertTree(self, root: Optional[TreeNode]) -> O...
51
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:\n if ...
11
101
symmetric-tree
<p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /...
57.534353
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["14", 0.0153], ["15", 0.0102], ["16", 0.0205], ["17", 0.0051], ["18", 0.046], ["19", 0.1125], ["20", 0.0921], ["21", 0.0307], ["22", 0.179], ["23", 0.486], ["24", 0.5729], ["25", 0.4195], ["26", 0.711], ["27", 2.1126], ["28", 1.775], ["29", 1.8057], ["30", 2.1024], ["31", 5.7701], ...
{"lang": "python3", "distribution": [["16000", 0.0051], ["16200", 0.0512], ["16300", 0.619], ["16400", 8.5784], ["16500", 29.224], ["16600", 46.2939]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSymmetric(self, root: Optional[TreeNode]) -> bool:\n if not root:\n ...
52
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSymmetric(self, root: Optional[TreeNode]) -> bool:\n if not root:\n ...
10
102
binary-tree-level-order-traversal
<p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level).</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ...
68.489866
Medium
[ "tree", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["16", 0.0065], ["18", 0.0065], ["19", 0.0326], ["20", 0.0228], ["21", 0.0163], ["22", 0.0522], ["23", 0.2055], ["24", 0.0816], ["25", 0.1664], ["26", 0.2838], ["27", 0.7177], ["28", 0.4698], ["29", 0.8058], ["30", 1.4876], ["31", 2.5478], ["32", 1.5235], ["33", 2.1465], ["34", 4.64...
{"lang": "python3", "distribution": [["16500", 0.0065], ["16600", 0.0065], ["16700", 0.0163], ["16800", 0.0424], ["16900", 0.3458], ["17000", 5.9242], ["17100", 23.7294], ["17200", 40.1318], ["17300", 19.9354]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:\n res=...
52
[ { "code": "from collections import deque\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrder(self, root: Optional[TreeNode]) -> L...
9
103
binary-tree-zigzag-level-order-traversal
<p>Given the <code>root</code> of a binary tree, return <em>the zigzag level order traversal of its nodes&#39; values</em>. (i.e., from left to right, then right to left for the next level and alternate between).</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetc...
59.986966
Medium
[ "tree", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["15", 0.0087], ["16", 0.0087], ["17", 0.0087], ["18", 0.0174], ["19", 0.1915], ["20", 0.0783], ["21", 0.1219], ["22", 0.1219], ["23", 0.8095], ["24", 0.3482], ["25", 0.6093], ["26", 1.0185], ["27", 2.5244], ["28", 1.3666], ["29", 1.6713], ["30", 3.508], ["31", 6.0063], ["32", 3.760...
{"lang": "python3", "distribution": [["16200", 0.0261], ["16300", 0.0261], ["16400", 0.1306], ["16500", 2.7507], ["16600", 18.0449], ["16700", 38.0397], ["16800", 34.2096]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:\n ...
48
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:\n ...
10
104
maximum-depth-of-binary-tree
<p>Given the <code>root</code> of a binary tree, return <em>its maximum depth</em>.</p> <p>A binary tree&#39;s <strong>maximum depth</strong>&nbsp;is the number of nodes along the longest path from the root node down to the farthest leaf node.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img ...
76.087873
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["13", 0.0021], ["15", 0.0042], ["16", 0.0042], ["18", 0.0063], ["19", 0.0294], ["20", 0.0084], ["21", 0.0126], ["22", 0.0463], ["23", 0.1409], ["24", 0.1199], ["25", 0.1451], ["26", 0.2881], ["27", 0.774], ["28", 0.4795], ["29", 0.6246], ["30", 1.2577], ["31", 2.8099], ["32", 1.653...
{"lang": "python3", "distribution": [["17000", 0.0042], ["17100", 0.0147], ["17200", 0.0694], ["17300", 1.0474], ["17400", 4.1264], ["17500", 12.1711], ["17600", 40.2654]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxDepth(self, root: Optional[TreeNode]) -> int:\n if not root:\n ...
53
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxDepth(self, root: Optional[TreeNode]) -> int:\n return self.solver(r...
7
105
construct-binary-tree-from-preorder-and-inorder-traversal
<p>Given two integer arrays <code>preorder</code> and <code>inorder</code> where <code>preorder</code> is the preorder traversal of a binary tree and <code>inorder</code> is the inorder traversal of the same tree, construct and return <em>the binary tree</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</s...
64.977993
Medium
[ "array", "hash-table", "divide-and-conquer", "tree", "binary-tree" ]
{"lang": "python3", "distribution": [["27", 0.0112], ["29", 0.0336], ["32", 0.10070000000000001], ["34", 0.151], ["37", 0.5255], ["39", 0.5982000000000001], ["42", 1.9175], ["44", 2.3984], ["46", 3.6171], ["49", 3.5054], ["51", 4.7632], ["54", 2.2754000000000003], ["56", 2.5046], ["59", 0.738], ["61", 0.3075], ["64", 0...
{"lang": "python3", "distribution": [["17546", 5.747199999999999], ["18440", 22.737199999999998], ["19334", 0.10639999999999997], ["20228", 0.0392], ["21121", 0.0336], ["22015", 0.0056], ["22909", 0.0168], ["23803", 0.0056], ["24696", 0.0056], ["25590", 0.0056], ["26484", 0.0056], ["27378", 0.0056], ["28271", 0.0112], ...
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]...
153
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]...
75
106
construct-binary-tree-from-inorder-and-postorder-traversal
<p>Given two integer arrays <code>inorder</code> and <code>postorder</code> where <code>inorder</code> is the inorder traversal of a binary tree and <code>postorder</code> is the postorder traversal of the same tree, construct and return <em>the binary tree</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
64.256831
Medium
[ "array", "hash-table", "divide-and-conquer", "tree", "binary-tree" ]
{"lang": "python3", "distribution": [["27", 0.048], ["29", 0.016], ["31", 0.032], ["33", 0.2558], ["35", 0.2877], ["37", 0.7511], ["39", 1.9658], ["42", 1.9179], ["44", 3.8836], ["46", 3.7558], ["48", 5.306], ["50", 5.3381], ["52", 5.290100000000001], ["55", 5.1302], ["57", 2.4772], ["59", 0.9909000000000001], ["61", 0...
{"lang": "python3", "distribution": [["17400", 0.032], ["17600", 0.0799], ["17700", 0.3196], ["17800", 0.5274], ["17900", 1.4863], ["18000", 1.2626], ["18100", 2.0617], ["18200", 6.4728], ["18300", 15.3908], ["18400", 5.6577], ["18500", 3.7558], ["18600", 3.8357], ["18700", 1.2786], ["18800", 0.1918], ["18900", 0.1918]...
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode...
148
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode...
69
107
binary-tree-level-order-traversal-ii
<p>Given the <code>root</code> of a binary tree, return <em>the bottom-up level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level from leaf to root).</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/02/...
64.300387
Medium
[ "tree", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["16", 0.0306], ["17", 0.0306], ["19", 0.1528], ["21", 0.0917], ["22", 0.2444], ["23", 0.2139], ["24", 0.4888], ["25", 0.4583], ["26", 0.6416], ["27", 1.711], ["28", 1.4971], ["29", 1.6804], ["30", 2.2915], ["31", 4.4913], ["32", 5.4079], ["33", 4.6135], ["34", 3.9413], ["35", 9.502...
{"lang": "python3", "distribution": [["16300", 0.0306], ["16400", 0.0306], ["16500", 0.3972], ["16600", 7.6077], ["16700", 28.1393], ["16800", 48.3654]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrderBottom(self, root: Optional[TreeNode]) -> List[List[int]]:\n\n ...
40
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrderBottom(self, root: Optional[TreeNode]) -> List[List[int]]:\n ...
9
108
convert-sorted-array-to-binary-search-tree
<p>Given an integer array <code>nums</code> where the elements are sorted in <strong>ascending order</strong>, convert <em>it to a </em><span data-keyword="height-balanced"><strong><em>height-balanced</em></strong></span> <em>binary search tree</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p>...
72.601618
Easy
[ "array", "divide-and-conquer", "tree", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["30", 0.0087], ["31", 0.0174], ["34", 0.0087], ["35", 0.0174], ["36", 0.0435], ["37", 0.087], ["38", 0.1565], ["39", 0.1565], ["40", 0.4174], ["41", 0.4783], ["42", 0.6696], ["43", 0.8696], ["44", 1.2436], ["45", 1.8697], ["46", 2.0524], ["47", 2.148], ["48", 3.9656], ["49", 4.5656...
{"lang": "python3", "distribution": [["17200", 0.0087], ["17300", 0.0087], ["17400", 0.0348], ["17500", 0.1739], ["17600", 2.5046], ["17700", 37.9163], ["17800", 49.8652]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedArrayToBST(self, nums: List[int]) -> TreeNode:\n root = self.trav...
48
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]:\n \n ...
11
109
convert-sorted-list-to-binary-search-tree
<p>Given the <code>head</code> of a singly linked list where elements are sorted in <strong>ascending order</strong>, convert <em>it to a </em><span data-keyword="height-balanced"><strong><em>height-balanced</em></strong></span> <em>binary search tree</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</stro...
62.737728
Medium
[ "linked-list", "divide-and-conquer", "tree", "binary-search-tree", "binary-tree" ]
{"lang": "python3", "distribution": [["72", 0.0415], ["77", 0.0415], ["78", 0.0415], ["79", 0.1246], ["80", 0.0415], ["81", 0.0831], ["82", 0.2493], ["83", 0.4155], ["84", 0.4985], ["85", 0.5401], ["86", 1.2879], ["87", 1.2048], ["88", 1.1633], ["89", 1.8695], ["90", 2.4927], ["91", 3.0744], ["92", 3.0328], ["93", 3.73...
{"lang": "python3", "distribution": [["19200", 0.0831], ["19300", 0.5401], ["19400", 2.3681], ["19500", 16.3689], ["19600", 17.5322], ["19700", 0.9555], ["19800", 0.0415], ["19900", 0.0415], ["20000", 0.0415], ["20200", 0.0415], ["20400", 0.1246], ["20500", 0.1246], ["20600", 0.3324], ["20700", 3.5729], ["20800", 19.94...
[ { "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# ...
56
[ { "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# ...
27
110
balanced-binary-tree
<p>Given a binary tree, determine if it is <span data-keyword="height-balanced"><strong>height-balanced</strong></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg" style="width: 342px; height: 221px;" /> <pre> <str...
53.384996
Easy
[ "tree", "depth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["21", 0.0044], ["22", 0.0089], ["23", 0.0133], ["24", 0.0266], ["26", 0.0754], ["27", 0.1376], ["28", 0.1597], ["29", 0.1376], ["30", 0.3017], ["31", 0.6168], ["32", 0.5635], ["33", 0.6079], ["34", 1.1892], ["35", 1.8592], ["36", 1.8548], ["37", 2.0678], ["38", 3.0307], ["39", 4.20...
{"lang": "python3", "distribution": [["16600", 0.0044], ["16900", 0.0044], ["17000", 0.0044], ["17100", 0.0799], ["17200", 0.2396], ["17300", 0.355], ["17400", 0.4215], ["17500", 5.0009], ["17600", 28.7407], ["17700", 43.1221]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isBalanced(self, root: Optional[TreeNode]) -> bool:\n def check(Node):\...
64
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isBalanced(self, root: Optional[TreeNode]) -> bool:\n # if root == None...
14
268
missing-number
<p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,0,1] <strong>Output...
68.090067
Easy
[ "array", "hash-table", "math", "binary-search", "bit-manipulation", "sorting" ]
{"lang": "python3", "distribution": [["33", 0.09100000000000001], ["53", 0.0315], ["73", 0.0175], ["94", 18.361599999999996], ["114", 62.673700000000004], ["134", 2.5714000000000006], ["155", 0.17500000000000007], ["175", 0.16100000000000003], ["196", 0.028], ["216", 0.0245], ["236", 0.0175], ["257", 0.0175], ["277", 0...
{"lang": "python3", "distribution": [["16900", 0.007], ["17100", 0.0175], ["17200", 0.0876], ["17300", 0.0701], ["17400", 0.049], ["17500", 0.2523], ["17600", 3.9344], ["17700", 44.8446], ["17800", 32.9538], ["17900", 3.0936], ["18000", 1.8498], ["18100", 1.2017], ["18200", 0.3153], ["18300", 0.2558], ["18400", 1.9129]...
[ { "code": "def missingNumber(nums: List[int]) -> int:\n return ((n:=len(nums)) * (n+1) // 2) - sum(nums)\n\nwith open('user.out', 'w') as f:\n for case in map(loads, stdin):\n f.write(f\"{missingNumber(case)}\\n\")\nexit(0)", "runtime": "33" }, { "code": "def missingNumber(nums: List[in...
121
[ { "code": "# class Solution:\n# def missingNumber(self, nums: List[int]) -> int:\n\n# n = len(nums)\n# nums.append(-1)\n# missing = n\n\n# i = 0\n# if n > 0:\n# next = i + 1\n \n# while i <= n:\n# curr = nums[i]\n# wh...
24
273
integer-to-english-words
<p>Convert a non-negative integer <code>num</code> to its English words representation.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 123 <strong>Output:</strong> &quot;One Hundred Twenty Three&quot; </pre> <p><strong class="example">Example 2:</strong></p> ...
34.015623
Hard
[ "math", "string", "recursion" ]
{"lang": "python3", "distribution": [["12", 0.0073], ["14", 0.0073], ["15", 0.0293], ["16", 0.0183], ["17", 0.0147], ["18", 0.0367], ["19", 0.0953], ["20", 0.1173], ["21", 0.088], ["22", 0.2456], ["23", 0.5314], ["24", 0.6927], ["25", 0.4142], ["26", 0.9713], ["27", 1.8656], ["28", 2.3017], ["29", 1.9938], ["30", 2.518...
{"lang": "python3", "distribution": [["15900", 0.0037], ["16000", 0.0037], ["16100", 0.0073], ["16200", 0.0037], ["16300", 0.1063], ["16400", 1.8362], ["16500", 14.459], ["16600", 30.8496], ["16700", 36.2117]]}
[ { "code": "class Solution:\n def numberToWords(self, num: int) -> str:\n if num == 0:\n return \"Zero\"\n\n ones_map = {\n 1: \"One\", \n 2: \"Two\", \n 3: \"Three\", \n 4: \"Four\", \n 5: \"Five\", \n 6: \"Six\", \n ...
48
[ { "code": "class Solution:\n def numberToWords(self,num: int) -> str:\n if num == 0: return \"Zero\"\n digits = list(map(int,str(num)))[::-1]\n if len(digits) % 3 == 2: digits.append(0) #make it a multiple of 3\n elif len(digits) % 3 == 1: \n digits.append(0)\n ...
13
274
h-index
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return <em>the researcher&#39;s h-index</em>.</p> <p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">defini...
39.359814
Medium
[ "array", "sorting", "counting-sort" ]
{"lang": "python3", "distribution": [["18", 0.0409], ["21", 0.1162], ["24", 0.3825], ["27", 1.4478], ["30", 4.6234], ["33", 9.765699999999999], ["36", 13.665199999999999], ["39", 18.432000000000002], ["42", 19.955], ["45", 12.2653], ["47", 5.9346], ["50", 1.4546999999999999], ["53", 0.4781], ["56", 0.3483], ["59", 0.30...
{"lang": "python3", "distribution": [["16100", 0.0068], ["16200", 0.0068], ["16400", 0.0137], ["16500", 0.0888], ["16600", 1.038], ["16700", 12.0399], ["16800", 28.1158], ["16900", 44.7722]]}
[ { "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:\n \n citations = sorted(citations, reverse = True)\n for i in range(len(citations)):\n if citations[i] <= i:\n return i\n\n return len(citations)", "runtime": "18" }, { ...
155
[ { "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:\n # 0, 1, 3, 5, 6\n citations.sort(key=lambda c: -c)\n h_index = 0\n print(citations)\n while h_index < len(citations) and citations[h_index] >= h_index + 1:\n print(h_index)\n ...
11
275
h-index-ii
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper and <code>citations</code> is sorted in <strong>ascending order</strong>, return <em>the researcher&#39;s h-index</em>.</p> <p>According to t...
38.435349
Medium
[ "array", "binary-search" ]
{"lang": "python3", "distribution": [["42", 0.1119], ["90", 0.0559], ["95", 0.0559], ["96", 0.0559], ["97", 0.1119], ["98", 0.0559], ["99", 0.1678], ["100", 0.1119], ["101", 0.5034], ["102", 0.5593], ["103", 0.7271], ["104", 0.8389], ["105", 1.2864], ["106", 1.1745], ["107", 2.2931], ["108", 2.4609], ["109", 2.9083], [...
{"lang": "python3", "distribution": [["20100", 0.1119], ["22900", 0.2237], ["23000", 0.5593], ["23100", 1.4541], ["23200", 3.7472], ["23300", 19.1834], ["23400", 60.8501]]}
[ { "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:\n left, right = 0, len(citations) - 1\n res = 0\n\n while left <= right:\n mid = (left + right) // 2\n if citations[mid] >= len(citations) - mid:\n res = len(citations) - mid\...
48
[ { "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:\n left, right = 0, len(citations) - 1\n res = 0\n\n while left <= right:\n mid = (left + right) // 2\n if citations[mid] >= len(citations) - mid:\n res = len(citations) - mid\...
11
171
excel-sheet-column-number
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
64.492023
Easy
[ "math", "string" ]
{"lang": "python3", "distribution": [["15", 0.0493], ["16", 0.0493], ["18", 0.0493], ["19", 0.0739], ["20", 0.0986], ["21", 0.1232], ["22", 0.419], ["23", 0.6655], ["24", 0.9613], ["25", 0.4683], ["26", 1.1585], ["27", 1.4789], ["28", 2.6128], ["29", 2.0705], ["30", 2.5881], ["31", 4.0424], ["32", 5.9404], ["33", 5.003...
{"lang": "python3", "distribution": [["16200", 0.3944], ["16300", 7.3946], ["16400", 26.7193], ["16500", 47.1038]]}
[ { "code": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n res = 0\n for ch in columnTitle:\n res = res * 26 + (ord(ch) - 64)\n return res", "runtime": "15" }, { "code": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n...
43
[ { "code": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n result =0 \n for char in columnTitle:\n result=result*26+(ord(char)-ord('A')+1)\n \n return result\n\n ", "memory": "16200" }, { "code": "class Solution:\n def titleTo...
7
172
factorial-trailing-zeroes
<p>Given an integer <code>n</code>, return <em>the number of trailing zeroes in </em><code>n!</code>.</p> <p>Note that <code>n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> n = 3 <strong>Output:</strong> 0 <strong...
43.823649
Medium
[ "math" ]
{"lang": "python3", "distribution": [["74", 74.21220000000002], ["193", 3.155], ["312", 2.1370000000000013], ["431", 1.2584000000000006], ["549", 0.9996000000000006], ["668", 0.1599], ["787", 0.23999999999999996], ["906", 0.14], ["1025", 0.06], ["1144", 0.0999], ["1263", 0.02], ["1382", 0.06], ["1501", 0.02], ["1619", ...
{"lang": "python3", "distribution": [["15900", 0.02], ["16100", 0.0399], ["16200", 0.7784], ["16300", 7.6846], ["16400", 23.992], ["16500", 40.3194], ["16600", 14.5509], ["16700", 4.5309], ["16800", 2.3952]]}
[ { "code": "class Solution:\n def trailingZeroes(self, n: int) -> int:\n count=0\n while(n>0):\n count+=n//5\n n=n//5\n return count\n ", "runtime": "74" }, { "code": "class Solution:\n def trailingZeroes(self, n: int) -> int:\n cnt = 0\n...
110
[ { "code": "class Solution:\n def trailingZeroes(self, n: int) -> int:\n m = 5\n ans = 0\n while n//m > 0:\n ans += n//m\n m *= 5\n return ans\n \n ", "memory": "16100" }, { "code": "class Solution:\n def trailingZeroes(self, n...
14
173
binary-search-tree-iterator
<p>Implement the <code>BSTIterator</code> class that represents an iterator over the <strong><a href="https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR)" target="_blank">in-order traversal</a></strong> of a binary search tree (BST):</p> <ul> <li><code>BSTIterator(TreeNode root)</code> Initializes an object o...
73.080149
Medium
[ "stack", "tree", "design", "binary-search-tree", "binary-tree", "iterator" ]
{"lang": "python3", "distribution": [["32", 0.0141], ["34", 0.0141], ["35", 0.0282], ["36", 0.0141], ["37", 0.0282], ["38", 0.0141], ["39", 0.1127], ["40", 0.1127], ["41", 0.0563], ["42", 0.3944], ["43", 0.338], ["44", 0.5915], ["45", 0.5211], ["46", 1.0704], ["47", 1.1268], ["48", 1.2254], ["49", 1.9577], ["50", 2.676...
{"lang": "python3", "distribution": [["21400", 0.0141], ["21600", 0.0141], ["21700", 0.0704], ["21800", 0.6338], ["21900", 4.1831], ["22000", 17.4648], ["22100", 6.9859], ["22200", 0.9718], ["22300", 5.0845], ["22400", 14.7465], ["22500", 31.0], ["22600", 13.4507]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: Optional[TreeNode]):\n self.stack = []\n ...
59
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: Optional[TreeNode]):\n # array containing all...
20
174
dungeon-game
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
38.489747
Hard
[ "array", "dynamic-programming", "matrix" ]
{"lang": "python3", "distribution": [["36", 0.0808], ["39", 0.0808], ["46", 0.0808], ["47", 0.1617], ["48", 0.1617], ["49", 0.0808], ["50", 0.5659], ["51", 0.485], ["52", 0.1617], ["53", 0.5659], ["54", 0.9701], ["55", 0.8892], ["56", 1.4551], ["57", 1.8593], ["58", 3.3145], ["59", 2.7486], ["60", 2.6677], ["61", 4.365...
{"lang": "python3", "distribution": [["17100", 0.1617], ["17200", 0.0808], ["17300", 0.0808], ["17400", 2.1827], ["17500", 15.9256], ["17600", 23.9289], ["17700", 15.7639], ["17800", 9.62], ["17900", 7.4373], ["18000", 4.8504], ["18100", 1.9402], ["18200", 0.3234], ["18300", 0.485], ["18400", 0.2425], ["18500", 0.2425]...
[ { "code": "class Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:\n height, width = len(dungeon), len(dungeon[0])\n m, n = height - 1, width - 1\n dp = [ [0] * width for _ in range(height) ]\n dp[m][n] = max(1,1 - dungeon[m][n])\n for r in range(m...
67
[ { "code": "class Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:\n height, width = len(dungeon), len(dungeon[0])\n m, n = height - 1, width - 1\n dp = [ [0] * width for _ in range(height) ]\n dp[m][n] = max(1,1 - dungeon[m][n])\n for r in range(m...
38
179
largest-number
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
39.733211
Medium
[ "array", "string", "greedy", "sorting" ]
{"lang": "python3", "distribution": [["18", 0.0427], ["20", 0.064], ["21", 0.0213], ["22", 0.064], ["23", 0.1281], ["24", 0.1494], ["25", 0.1494], ["26", 0.2988], ["27", 0.7684], ["28", 0.4055], ["29", 0.5977], ["30", 1.302], ["31", 1.4514], ["32", 1.6222], ["33", 1.8143], ["34", 3.5219], ["35", 5.0374], ["36", 3.4792]...
{"lang": "python3", "distribution": [["16100", 0.0427], ["16200", 0.1921], ["16300", 3.2444], ["16400", 21.9851], ["16500", 41.5795]]}
[ { "code": "class Solution:\n def largestNumber(self, nums: List[int]) -> str:\n snums = list(map(str, nums))\n print(snums)\n snums.sort(key=lambda x: x*10, reverse = True)\n\n if snums[0] == \"0\":\n return \"0\"\n \n return ''.join(snums)\n\n", "runt...
67
[ { "code": "class Solution:\n def largestNumber(self, nums: List[int]) -> str:\n # convert to string so we can compare\n for i, n in enumerate(nums):\n nums[i] = str(n)\n \n def compare(n1: str, n2: str):\n if n1 + n2 > n2 + n1:\n return -1\n ...
8
187
repeated-dna-sequences
<p>The <strong>DNA sequence</strong> is composed of a series of nucleotides abbreviated as <code>&#39;A&#39;</code>, <code>&#39;C&#39;</code>, <code>&#39;G&#39;</code>, and <code>&#39;T&#39;</code>.</p> <ul> <li>For example, <code>&quot;ACGAATTCCG&quot;</code> is a <strong>DNA sequence</strong>.</li> </ul> <p>When s...
49.638096
Medium
[ "hash-table", "string", "bit-manipulation", "sliding-window", "rolling-hash", "hash-function" ]
{"lang": "python3", "distribution": [["35", 0.0552], ["36", 0.0552], ["37", 0.0552], ["38", 0.1656], ["39", 0.1656], ["40", 0.138], ["41", 0.3036], ["42", 0.5244], ["43", 0.6624], ["44", 0.6624], ["45", 1.0213], ["46", 1.2973], ["47", 1.7113], ["48", 1.3249], ["49", 2.2633], ["50", 2.2909], ["51", 3.119], ["52", 2.8982...
{"lang": "python3", "distribution": [["16800", 0.0552], ["16900", 0.4968], ["17000", 0.6624], ["17100", 0.0552], ["17200", 0.0276], ["17300", 0.0828], ["17400", 0.0276], ["20800", 0.0552], ["23700", 0.0276], ["24000", 0.0276], ["26100", 0.0828], ["26200", 1.1317], ["26300", 1.1317], ["26400", 0.1104], ["26500", 0.7452]...
[ { "code": "class Solution:\n \n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n map = {}\n result = []\n\n for i in range(len(s) - 9):\n substring = s[i:i + 10]\n if substring in map:\n if map[substring] == 1:\n result...
89
[ { "code": "class Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n res = set()\n for idx in range(len(s) - 10):\n if s[idx: idx + 10] in s[idx + 1:]:\n res.add(s[idx: idx + 10] )\n return list(res)\n", "memory": "16800" }, { "cod...
65
188
best-time-to-buy-and-sell-stock-iv
<p>You are given an integer array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day, and an integer <code>k</code>.</p> <p>Find the maximum profit you can achieve. You may complete at most <code>k</code> transactions: i.e. you may buy at most <code>k<...
44.534594
Hard
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["28", 0.109], ["32", 0.109], ["36", 0.19619999999999999], ["40", 0.3488], ["44", 0.43600000000000005], ["48", 0.37060000000000004], ["52", 0.6104], ["56", 0.30519999999999997], ["60", 0.2616], ["63", 0.3052], ["67", 0.37060000000000004], ["71", 0.7629000000000001], ["75", 1.9398], ...
{"lang": "python3", "distribution": [["16623", 31.4081], ["17469", 11.8569], ["18315", 1.3514000000000002], ["19161", 5.645199999999999], ["20008", 0.8719000000000001], ["20854", 2.6809], ["21700", 3.2476], ["22546", 0.872], ["23393", 0.8937], ["24239", 2.3323], ["25085", 0.30519999999999997], ["25931", 3.0297], ["2677...
[ { "code": "class DoubleLinkListNode:\n def __init__(self, ind, pre = None, next = None):\n self.ind = ind\n self.pre = pre if pre else self\n self.next = next if next else self\n\nclass Solution:\n def MinMaxList(self, arr: List[int]) -> List[int]:\n n = len(arr)\n if n ...
156
[ { "code": "class Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n dp = [0] * (2 * k + 1)\n for i in range(1, 2 * k + 1, 2):\n dp[i] = -prices[0]\n \n for i in range(1, len(prices)):\n for m in range(1, 2 * k + 1):\n if m % 2...
120
189
rotate-array
<p>Given an integer array <code>nums</code>, rotate the array to the right by <code>k</code> steps, where <code>k</code> is non-negative.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4,5,6,7], k = 3 <strong>Output:</strong> [5,6,7,1,2,3,4] <strong>Ex...
41.548309
Medium
[ "array", "math", "two-pointers" ]
{"lang": "python3", "distribution": [["46", 0.0491], ["60", 0.0054], ["74", 0.0082], ["87", 0.0055], ["101", 0.0192], ["115", 0.011], ["128", 0.5276], ["142", 15.583200000000001], ["156", 50.490500000000004], ["170", 14.665300000000002], ["183", 1.2369], ["197", 0.2554], ["211", 0.1867], ["224", 0.15360000000000001], [...
{"lang": "python3", "distribution": [["21700", 0.0082], ["21800", 0.0385], ["21900", 0.0082], ["25200", 0.0027], ["25600", 0.0055], ["25700", 0.0027], ["25800", 0.011], ["25900", 0.0027], ["26000", 0.0027], ["26200", 0.0027], ["26300", 0.0027], ["26400", 0.0082], ["26500", 0.011], ["26600", 0.0055], ["26700", 0.011], [...
[ { "code": "def rotate(nums: List[int], k: int) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"\n k = k%len(nums)\n nums[:] = nums[-k:] + nums[:-k]\n\nwith open(\"user.out\", \"w\") as Solution:\n for nums, k in zip(map(loads, stdin), map(int, stdin)):\n ...
131
[ { "code": "def rotate(nums: List[int], k: int) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"\n k = k%len(nums)\n nums[:] = nums[-k:] + nums[:-k]\n\nwith open(\"user.out\", \"w\") as Solution:\n for nums, k in zip(map(loads, stdin), map(int, stdin)):\n ...
35
190
reverse-bits
<p>Reverse bits of a given 32 bits unsigned integer.</p> <p><strong>Note:</strong></p> <ul> <li>Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer&#39;s in...
60.210901
Easy
[ "divide-and-conquer", "bit-manipulation" ]
{"lang": "python3", "distribution": [["11", 0.0094], ["15", 0.0094], ["16", 0.0189], ["17", 0.0094], ["18", 0.0189], ["19", 0.1511], ["20", 0.1228], ["21", 0.1417], ["22", 0.3306], ["23", 0.6045], ["24", 0.614], ["25", 0.6517], ["26", 1.1051], ["27", 2.6353], ["28", 2.1158], ["29", 1.7947], ["30", 2.9565], ["31", 5.875...
{"lang": "python3", "distribution": [["16100", 0.0283], ["16200", 0.1606], ["16300", 1.8041], ["16400", 16.2274], ["16500", 37.0454], ["16600", 38.5189]]}
[ { "code": "class Solution:\n def reverseBits(self, n: int) -> int:\n if n == 0:\n return 0\n output = 0\n cnt = 31\n while n != 0:\n num = n % 2\n output = output + num * pow(2, cnt)\n n = int (n / 2)\n cnt = cnt - 1\n\n ...
50
[ { "code": "class Solution:\n def reverseBits(self, n: int) -> int:\n \n res, power = 0, 31\n while n :\n res += (n&1)<<power\n n = n >> 1\n power -=1\n \n return res", "memory": "16100" }, { "code": "class Solution:\n def reve...
10
11
container-with-most-water
<p>You are given an integer array <code>height</code> of length <code>n</code>. There are <code>n</code> vertical lines drawn such that the two endpoints of the <code>i<sup>th</sup></code> line are <code>(i, 0)</code> and <code>(i, height[i])</code>.</p> <p>Find two lines that together with the x-axis form a container...
56.156127
Medium
[ "array", "two-pointers", "greedy" ]
{"lang": "python3", "distribution": [["43", 0.0038], ["49", 0.0038], ["56", 0.028], ["62", 0.0374], ["69", 0.041], ["75", 0.0131], ["82", 0.0056], ["89", 0.0019], ["95", 0.0075], ["102", 0.0019], ["108", 0.0019], ["115", 0.0037], ["121", 0.0094], ["128", 0.0076], ["134", 0.014900000000000002], ["141", 0.0094], ["147", ...
{"lang": "python3", "distribution": [["20900", 0.0056], ["21100", 0.0037], ["24400", 0.0112], ["24500", 0.0149], ["24600", 0.0019], ["24700", 0.0466], ["24800", 0.1659], ["24900", 0.0224], ["25000", 0.0037], ["25300", 0.0019], ["25500", 0.0093], ["25600", 0.0354], ["25700", 0.0037], ["25800", 0.0037], ["25900", 0.0056]...
[ { "code": "def maxArea(height: List[int]) -> int:\n maxH, maxA, left, right = max(height), 0, 0, len(height) - 1\n while left < right:\n #currArea = \n #maxA = max(min(height[left], height[right]) * (right - left), maxA)\n if height[left] < height[right]:\n if height[left] ...
116
[ { "code": "class Solution:\n def maxArea(self, height: List[int]) -> int:\n left, right = 0, len(height)-1\n max_area = 0\n\n while left < right:\n max_area = max(max_area, min(height[left], height[right])* (right-left))\n if height[left] < height[right]:\n ...
67
12
integer-to-roman
<p>Seven different symbols represent Roman numerals with the following values:</p> <table> <thead> <tr> <th>Symbol</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>I</td> <td>1</td> </tr> <tr> <td>V</td> <td>5</td> </tr> <tr> <td>X</td> <td>10</td> </tr> <tr> <td>L</t...
66.268375
Medium
[ "hash-table", "math", "string" ]
{"lang": "python3", "distribution": [["15", 0.0055], ["18", 0.0055], ["19", 0.011], ["20", 0.011], ["21", 0.0055], ["23", 0.0165], ["24", 0.0441], ["25", 0.0221], ["26", 0.0276], ["27", 0.1213], ["28", 0.1544], ["29", 0.1213], ["30", 0.3363], ["31", 0.5348], ["32", 0.6064], ["33", 0.5017], ["34", 1.0199], ["35", 1.3286...
{"lang": "python3", "distribution": [["16100", 0.011], ["16200", 0.0496], ["16300", 0.4245], ["16400", 8.5065], ["16500", 34.1199], ["16600", 39.8534]]}
[ { "code": "class Solution:\n def intToRoman(self, num: int) -> str:\n digits =[(1000, \"M\"),\n (900,\"CM\"),(500,\"D\"),(400,\"CD\"), (100, \"C\"), \n (90, \"XC\"),(50, \"L\"),(40, \"XL\"),(10, \"X\"),\n (9, \"IX\"),(5, \"V\"),(4, \"IV\"),(1, \"I\")]\n\n roman_digits = []...
74
[ { "code": "class Solution:\n def intToRoman(self, num: int) -> str:\n symbols= [['M',1000],['CM',900],['D',500],['CD',400],['C',100],['XC',90],['L',50],\n ['XL',40],['X',10],['IX',9],['V',5],['IV',4],['I',1]]\n ans = \"\"\n \n for sym,value in symbols:\n res = nu...
10
13
roman-to-integer
<p>Roman numerals are represented by seven different symbols:&nbsp;<code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p> <pre> <strong>Symbol</strong> <strong>Value</strong> I 1 V 5 X 10 L 50 C ...
62.649052
Easy
[ "hash-table", "math", "string" ]
{"lang": "python3", "distribution": [["19", 0.0057], ["20", 0.0057], ["21", 0.0038], ["22", 0.0114], ["23", 0.0438], ["24", 0.0286], ["25", 0.0228], ["26", 0.0666], ["27", 0.1409], ["28", 0.1599], ["29", 0.1428], ["30", 0.3123], ["31", 0.457], ["32", 0.6074], ["33", 0.4646], ["34", 0.9863], ["35", 1.4109], ["36", 1.609...
{"lang": "python3", "distribution": [["15900", 0.0038], ["16000", 0.0057], ["16100", 0.0171], ["16200", 0.0533], ["16300", 0.4836], ["16400", 10.8744], ["16500", 41.9228], ["16600", 39.4665]]}
[ { "code": "class Solution:\n def romanToInt(self, s: str) -> int:\n # dic = {\n # 'I': 1,\n # 'V': 5,\n # 'X': 10,\n # 'L': 50,\n # 'C': 100,\n # 'D': 500,\n # 'M': 1000\n # }\n ...
65
[ { "code": "class Solution:\n def romanToInt(self, s: str) -> int:\n d = {'I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000}\n prev = d[s[-1]]\n num = d[s[-1]]\n for i in s[-2::-1]:\n if d[i] >= prev:\n num += d[i]\n else:\n...
12
14
longest-common-prefix
<p>Write a function to find the longest common prefix string amongst an array of strings.</p> <p>If there is no common prefix, return an empty string <code>&quot;&quot;</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> strs = [&quot;flower&quot;,&quot;flow&quo...
43.786512
Easy
[ "string", "trie" ]
{"lang": "python3", "distribution": [["15", 0.013], ["16", 0.0093], ["17", 0.0056], ["18", 0.0186], ["19", 0.0671], ["20", 0.069], ["21", 0.0485], ["22", 0.1864], ["23", 0.3989], ["24", 0.4716], ["25", 0.3448], ["26", 0.7064], ["27", 1.4482], ["28", 1.4892], ["29", 1.4911], ["30", 2.1453], ["31", 3.8246], ["32", 4.1135...
{"lang": "python3", "distribution": [["16000", 0.0019], ["16100", 0.0037], ["16200", 0.0149], ["16300", 0.2703], ["16400", 4.4695], ["16500", 24.0811], ["16600", 41.2659]]}
[ { "code": "class Solution:\n def longestCommonPrefix(self, strs: List[str]) -> str:\n \n word=strs[0]\n \n \n for i in strs:\n if len(i)<len(word):\n word=i\n print(word)\n if len(word)<1:\n return word\n str1=''\n ...
55
[ { "code": "class Solution:\n def longestCommonPrefix(self, strs: List[str]) -> str:\n prefix = \"\"\n for i in range(len(strs[0])):\n if all([i < len(word) and word[i] == strs[0][i] for word in strs]):\n prefix += strs[0][i]\n else:\n break\n ...
11
15
3sum
<p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p> <p>Notice that the solution set must not contain duplicate triplets.</p> <p>&nbsp;</p> <p...
35.343599
Medium
[ "array", "two-pointers", "sorting" ]
{"lang": "python3", "distribution": [["135", 0.0325], ["160", 0.0034], ["185", 0.0243], ["209", 0.0363], ["234", 0.0050999999999999995], ["259", 0.0068], ["284", 0.0225], ["309", 0.0744], ["333", 0.043], ["358", 0.1936], ["383", 0.10399999999999998], ["408", 0.050100000000000006], ["433", 0.09839999999999999], ["457", ...
{"lang": "python3", "distribution": [["18200", 0.0035], ["18300", 0.0017], ["18400", 0.0035], ["18600", 0.0035], ["18800", 0.0035], ["18900", 0.0121], ["19000", 0.0104], ["19100", 0.019], ["19200", 0.0155], ["19300", 0.0155], ["19400", 0.0155], ["19500", 0.0242], ["19600", 0.0224], ["19700", 0.0742], ["19800", 0.7918],...
[ { "code": "def threeSum(nums: List[int]) -> List[List[int]]:\n nums.sort()\n index = 1\n x = nums[0]\n counter = 1\n while index < len(nums):\n if nums[index] == x:\n counter = counter + 1\n if x == 0:\n if counter > 3:\n nums.pop(ind...
154
[ { "code": "class Solution:\n def threeSum(self, nums: List[int]) -> List[List[int]]:\n nums.sort()\n n = len(nums)\n res = set()\n for i in range(n-2):\n l = i+1\n r = n-1\n while l < r:\n s = nums[i] + nums[l] + nums[r]\n ...
58
16
3sum-closest
<p>Given an integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>.</p> <p>Return <em>the sum of the three integers</em>.</p> <p>You may assume that each input would have exactly one solu...
46.07577
Medium
[ "array", "two-pointers", "sorting" ]
{"lang": "python3", "distribution": [["39", 0.184], ["49", 0.7369], ["59", 1.7316], ["69", 0.5156999999999999], ["79", 0.30390000000000006], ["89", 0.1012], ["99", 0.046], ["109", 0.0552], ["119", 0.0184], ["129", 0.0184], ["139", 0.0552], ["149", 0.0276], ["159", 0.0276], ["169", 0.0092], ["179", 0.0092], ["189", 0.00...
{"lang": "python3", "distribution": [["16000", 0.0092], ["16100", 0.0092], ["16200", 0.0276], ["16300", 0.304], ["16400", 2.9106], ["16500", 19.7476], ["16600", 35.5623], ["16700", 34.0149]]}
[ { "code": "def threeSumClosest(nums: List[int], target: int) -> int:\n if (n := len(nums)) <= 8:\n return min((sum(pair) for pair in combinations(nums, 3)), key=lambda x: abs(target-x))\n nums.sort()\n\n closest_so_far = 100000\n\n i, ell = 0, n\n x = nums\n while i+2 < ell:\n z_...
149
[ { "code": "class Solution:\n def threeSumClosest(self, nums: List[int], target: int) -> int:\n diff=float('inf')\n nums.sort()\n for i in range(len(nums)-1):\n start=i+1\n end=len(nums)-1\n while(start<end):\n current= nums[i]+ nums[start]+...
13
17
letter-combinations-of-a-phone-number
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
61.705974
Medium
[ "hash-table", "string", "backtracking" ]
{"lang": "python3", "distribution": [["9", 0.0033], ["12", 0.0033], ["14", 0.0067], ["15", 0.0167], ["16", 0.0267], ["17", 0.0233], ["18", 0.0901], ["19", 0.1868], ["20", 0.1734], ["21", 0.1568], ["22", 0.5604], ["23", 0.7505], ["24", 0.7238], ["25", 0.9973], ["26", 2.3349], ["27", 2.1681], ["28", 1.8012], ["29", 3.068...
{"lang": "python3", "distribution": [["16000", 0.0033], ["16100", 0.01], ["16200", 0.0767], ["16300", 1.521], ["16400", 14.9666], ["16500", 34.3229], ["16600", 40.7138]]}
[ { "code": "class Solution:\n def letterCombinations(self, digits: str) -> List[str]:\n if not digits:\n return []\n \n digit_to_letters = {\n '2': 'abc',\n '3': 'def',\n '4': 'ghi',\n '5': 'jkl',\n '6': 'mno',\n ...
50
[ { "code": "class Solution:\n def letterCombinations(self, digits: str) -> List[str]:\n if not digits:\n return []\n \n # Mapping of digits to corresponding letters\n phone = {\n '2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl',\n '6': 'mno', '7': 'pq...
11
18
4sum
<p>Given an array <code>nums</code> of <code>n</code> integers, return <em>an array of all the <strong>unique</strong> quadruplets</em> <code>[nums[a], nums[b], nums[c], nums[d]]</code> such that:</p> <ul> <li><code>0 &lt;= a, b, c, d&nbsp;&lt; n</code></li> <li><code>a</code>, <code>b</code>, <code>c</code>, and <c...
36.733172
Medium
[ "array", "two-pointers", "sorting" ]
{"lang": "python3", "distribution": [["48", 1.1082], ["62", 4.6398], ["75", 1.3456000000000004], ["88", 0.2376], ["102", 0.4059], ["115", 0.33659999999999995], ["129", 0.3267], ["142", 0.1386], ["155", 0.1584], ["169", 0.11880000000000002], ["182", 0.0495], ["196", 0.1386], ["209", 0.0693], ["222", 0.10890000000000002]...
{"lang": "python3", "distribution": [["16100", 0.0396], ["16200", 0.0989], ["16300", 0.5243], ["16400", 4.0265], ["16500", 25.1187], ["16600", 41.947], ["16700", 16.7392], ["16800", 5.4412]]}
[ { "code": "class Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n res = []\n n = len(nums)\n if n < 4:\n return res\n nums.sort()\n \n for i in range(n - 3):\n # Skip duplicate elements for the first number\n ...
148
[ { "code": "class Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n nums.sort() # Sort the array first\n n = len(nums)\n result = []\n \n for a in range(n - 3):\n # Skip duplicates for a\n if a > 0 and nums[a] == nums[a-...
14
19
remove-nth-node-from-end-of-list
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
46.703639
Medium
[ "linked-list", "two-pointers" ]
{"lang": "python3", "distribution": [["14", 0.0031], ["15", 0.0183], ["16", 0.0153], ["17", 0.0092], ["18", 0.0244], ["19", 0.1099], ["20", 0.0885], ["21", 0.0702], ["22", 0.1862], ["23", 0.6592], ["24", 0.415], ["25", 0.4517], ["26", 0.8179], ["27", 2.5848], ["28", 1.5991], ["29", 1.7059], ["30", 2.1118], ["31", 6.506...
{"lang": "python3", "distribution": [["16000", 0.0061], ["16100", 0.0336], ["16200", 0.2747], ["16300", 5.2704], ["16400", 26.4954], ["16500", 46.2341]]}
[ { "code": "class Solution:\n def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:\n fast = slow = head\n for _ in range(n):\n fast = fast.next\n if not fast:\n return head.next\n while fast.next:\n fast = fast.next\n slow = sl...
49
[ { "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:\n newList = ListNode()\n n...
9
20
valid-parentheses
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
41.034715
Easy
[ "string", "stack" ]
{"lang": "python3", "distribution": [["10", 0.0014], ["11", 0.0042], ["12", 0.0042], ["14", 0.0042], ["15", 0.0391], ["16", 0.0279], ["17", 0.0209], ["18", 0.0698], ["19", 0.1814], ["20", 0.1172], ["21", 0.1967], ["22", 0.6083], ["23", 0.7227], ["24", 0.6264], ["25", 0.8817], ["26", 2.1862], ["27", 2.2197], ["28", 1.80...
{"lang": "python3", "distribution": [["15800", 0.0014], ["15900", 0.0028], ["16000", 0.0028], ["16100", 0.0056], ["16200", 0.0432], ["16300", 0.5162], ["16400", 9.5958], ["16500", 39.0334], ["16600", 41.6228]]}
[ { "code": "class Solution:\n def isValid(self, s: str) -> bool:\n open_braces = [\"(\", \"[\", \"{\"]\n close_braces = [\")\", \"]\", \"}\"]\n\n # use a list as stack\n stack = []\n\n for c in s:\n if c in open_braces:\n # push an open brace onto s...
54
[ { "code": "class Solution:\n def isValid(self, s: str) -> bool:\n \n old_brackets = []\n for bracket in s:\n if(bracket in [\"(\", \"[\", \"{\"]):\n old_brackets.append(bracket)\n continue\n if(old_brackets and old_brackets[-1] == \"(\"...
14
111
minimum-depth-of-binary-tree
<p>Given a binary tree, find its minimum depth.</p> <p>The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.</p> <p><strong>Note:</strong>&nbsp;A leaf is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt...
48.931229
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["174", 0.0395], ["176", 0.0099], ["178", 0.0198], ["180", 0.0099], ["182", 0.0296], ["183", 0.0296], ["185", 0.09870000000000001], ["187", 0.1876], ["189", 0.2172], ["191", 0.3357], ["193", 0.2073], ["194", 0.5628], ["196", 0.4838], ["198", 0.7603], ["200", 0.8392999999999999], ["2...
{"lang": "python3", "distribution": [["32299", 0.0099], ["41600", 0.0099], ["41700", 0.0099], ["41900", 0.0099], ["42200", 0.0099], ["42300", 0.0395], ["42400", 0.0987], ["42500", 0.2271], ["42600", 0.1382], ["42700", 0.3061], ["42800", 0.1086], ["42900", 0.4542], ["43000", 4.3345], ["43100", 19.2239], ["43200", 19.362...
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDepth(self, root: Optional[TreeNode]) -> int:\n minDepth= float('inf...
144
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDepth(self, root: Optional[TreeNode]) -> int:\n \n if(root ==...
24
112
path-sum
<p>Given the <code>root</code> of a binary tree and an integer <code>targetSum</code>, return <code>true</code> if the tree has a <strong>root-to-leaf</strong> path such that adding up all the values along the path equals <code>targetSum</code>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;...
51.350279
Easy
[ "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["19", 0.0055], ["20", 0.0164], ["21", 0.0055], ["22", 0.0218], ["23", 0.0982], ["24", 0.1528], ["25", 0.0873], ["26", 0.251], ["27", 0.4966], ["28", 0.4911], ["29", 0.5348], ["30", 0.7967], ["31", 2.1774], ["32", 1.8608], ["33", 1.8881], ["34", 2.0737], ["35", 4.7913], ["36", 4.600...
{"lang": "python3", "distribution": [["16800", 0.0055], ["16900", 0.0055], ["17000", 0.0109], ["17100", 0.1146], ["17200", 1.4407], ["17300", 15.2578], ["17400", 34.4065], ["17500", 41.8063]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n i...
52
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n i...
12
113
path-sum-ii
<p>Given the <code>root</code> of a binary tree and an integer <code>targetSum</code>, return <em>all <strong>root-to-leaf</strong> paths where the sum of the node values in the path equals </em><code>targetSum</code><em>. Each path should be returned as a list of the node <strong>values</strong>, not node references</...
59.172249
Medium
[ "backtracking", "tree", "depth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["16", 0.013], ["21", 0.0261], ["22", 0.0261], ["23", 0.0391], ["24", 0.0912], ["25", 0.0391], ["26", 0.2215], ["27", 0.2475], ["28", 0.3517], ["29", 0.4169], ["30", 0.6514], ["31", 0.964], ["32", 1.6675], ["33", 1.3679], ["34", 1.9672], ["35", 2.8921], ["36", 4.0516], ["37", 3.7259...
{"lang": "python3", "distribution": [["16900", 0.013], ["17100", 0.013], ["17200", 0.2606], ["17300", 3.0745], ["17400", 25.9901], ["17500", 30.7191], ["17600", 3.5696], ["17700", 1.2767], ["17800", 1.1725], ["17900", 0.5211], ["18000", 0.1824], ["18100", 0.0912], ["18200", 0.1303], ["18300", 0.1694], ["18400", 0.0651]...
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: Optional[TreeNode], targetSum: int) -> List[List[int]]:\n ...
53
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: Optional[TreeNode], targetSum: int) -> List[List[int]]:\n ...
45
114
flatten-binary-tree-to-linked-list
<p>Given the <code>root</code> of a binary tree, flatten the tree into a &quot;linked list&quot;:</p> <ul> <li>The &quot;linked list&quot; should use the same <code>TreeNode</code> class where the <code>right</code> child pointer points to the next node in the list and the <code>left</code> child pointer is always <c...
66.348012
Medium
[ "linked-list", "stack", "tree", "depth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["18", 0.0232], ["19", 0.0811], ["20", 0.0695], ["21", 0.0464], ["22", 0.1275], ["23", 0.2318], ["24", 0.255], ["25", 0.2202], ["26", 0.9735], ["27", 0.8112], ["28", 1.1473], ["29", 1.2748], ["30", 2.5611], ["31", 1.8774], ["32", 3.2796], ["33", 3.6968], ["34", 5.7712], ["35", 4.229...
{"lang": "python3", "distribution": [["16200", 0.0116], ["16400", 0.0232], ["16500", 0.3477], ["16600", 6.6636], ["16700", 50.7938]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n prev = None\n def flatten(self, root: Optional[TreeNode]) -> None:\n \"\...
52
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flatten(self, root: Optional[TreeNode]) -> None:\n \"\"\"\n Do n...
7
115
distinct-subsequences
<p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p> <p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s...
48.277329
Hard
[ "string", "dynamic-programming" ]
{"lang": "python3", "distribution": [["31", 0.5093], ["40", 1.6254], ["49", 2.4088999999999996], ["58", 0.7833999999999999], ["67", 0.098], ["76", 0.13720000000000002], ["85", 0.0588], ["94", 0.098], ["104", 0.098], ["113", 0.3919], ["122", 0.3526], ["131", 0.4506], ["140", 0.5289], ["149", 0.3526], ["158", 0.235100000...
{"lang": "python3", "distribution": [["17374", 13.4353], ["19323", 0.4506], ["21271", 3.7016000000000004], ["23220", 0.0784], ["25169", 5.6795], ["27118", 0.0196], ["29066", 1.6844], ["31015", 2.9378999999999995], ["32964", 0.2938], ["34913", 0.1567], ["36861", 0.1568], ["38810", 0.0196], ["40759", 0.098], ["42708", 0....
[ { "code": "class Solution:\n \n def numDistinct(self, s: str, t: str) -> int:\n b=[0 for i in range(len(t))]\n e=[0 for i in range(len(t))]\n \n j=0\n for i in range(len(t)):\n while( j < len(s)):\n if t[i]==s[j]:\n b[i]=j\n ...
152
[ { "code": "class Solution:\n def numDistinct(self, s: str, t: str) -> int:\n m, n = len(s), len(t)\n if m < n:\n return 0\n \n dp = [0] * (n + 1)\n dp[0] = 1\n \n for i in range(1, m + 1):\n for j in range(min(i, n), 0, -1):\n ...
110
116
populating-next-right-pointers-in-each-node
<p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p> <pre> struct Node { int val; Node *left; Node *right; Node *next; } </pre> <p>Populate each next pointer to point to its next rig...
63.627273
Medium
[ "linked-list", "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["29", 0.0337], ["30", 0.0505], ["31", 0.1347], ["32", 0.2189], ["33", 0.0842], ["34", 0.4714], ["35", 0.6566], ["36", 0.7912], ["37", 0.6566], ["38", 1.4478], ["39", 1.734], ["40", 1.8687], ["41", 2.4074], ["42", 3.8047], ["43", 3.9899], ["44", 3.6027], ["45", 4.798], ["46", 6.5152...
{"lang": "python3", "distribution": [["17600", 0.0337], ["17700", 0.1852], ["17800", 4.798], ["17900", 21.3131], ["18000", 37.2054], ["18100", 27.6936]]}
[ { "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self...
84
[ { "code": "class Solution:\n def connect(self, root: 'Optional[Node]') -> 'Optional[Node]':\n if not root:\n return None\n \n leftmost = root\n while leftmost.left:\n current = leftmost\n while current:\n # Connect left child to righ...
10
117
populating-next-right-pointers-in-each-node-ii
<p>Given a binary tree</p> <pre> struct Node { int val; Node *left; Node *right; Node *next; } </pre> <p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p> <p>Initially, all next pointers are set to <code>NULL</...
53.552528
Medium
[ "linked-list", "tree", "depth-first-search", "breadth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["23", 0.0175], ["24", 0.0524], ["25", 0.0349], ["26", 0.1572], ["27", 0.2096], ["28", 0.1397], ["29", 0.3319], ["30", 0.8035], ["31", 0.6463], ["32", 0.8559], ["33", 0.9782], ["34", 2.2358], ["35", 1.9563], ["36", 2.2358], ["37", 3.2489], ["38", 4.8559], ["39", 4.5939], ["40", 4.55...
{"lang": "python3", "distribution": [["16600", 0.0175], ["17200", 0.0349], ["17300", 0.0873], ["17400", 1.9039], ["17500", 15.8428], ["17600", 33.4847], ["17700", 40.4716]]}
[ { "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self...
46
[ { "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\n\n\nclass Solution:\n def connect(...
11
118
pascals-triangle
<p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal&#39;s triangle</strong>.</p> <p>In <strong>Pascal&#39;s triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p> <img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn...
75.375601
Easy
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["15", 0.0338], ["16", 0.0056], ["17", 0.0113], ["18", 0.0394], ["19", 0.1407], ["20", 0.1069], ["21", 0.0675], ["22", 0.18], ["23", 0.7877], ["24", 0.3207], ["25", 0.4613], ["26", 0.7427], ["27", 2.3855], ["28", 1.3447], ["29", 1.8454], ["30", 2.5655], ["31", 6.0763], ["32", 3.7583...
{"lang": "python3", "distribution": [["15900", 0.0056], ["16000", 0.0113], ["16100", 0.0113], ["16200", 0.1069], ["16300", 1.9185], ["16400", 18.7915], ["16500", 48.194]]}
[ { "code": "class Solution:\n def generate(self, numRows: int) -> List[List[int]]:\n l = [[1], [1,1]]\n k = [1,1]\n counter = 3\n if numRows == 1:\n return [[1]]\n\n for _ in range(2,numRows):\n a = [1]\n for i in range(len(k)-1):\n ...
46
[ { "code": "class Solution:\n memo = {}\n\n def getRow(self, rowNum): \n if rowNum in self.memo:\n return self.memo[rowNum]\n\n rows = [0 for _ in range(rowNum)]\n rows[0] = 1\n rows[-1] = 1\n\n for i in range(1, len(rows) - 1):\n prev_row...
11
119
pascals-triangle-ii
<p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal&#39;s triangle</strong>.</p> <p>In <strong>Pascal&#39;s triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p> <img alt="" src="https://u...
64.67461
Easy
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["12", 0.0128], ["14", 0.0128], ["15", 0.0128], ["16", 0.0128], ["17", 0.0257], ["18", 0.0898], ["19", 0.0898], ["20", 0.1539], ["21", 0.2566], ["22", 0.372], ["23", 0.5773], ["24", 0.8852], ["25", 1.052], ["26", 2.2065], ["27", 2.2065], ["28", 2.4759], ["29", 2.9634], ["30", 5.914]...
{"lang": "python3", "distribution": [["16100", 0.0513], ["16200", 0.372], ["16300", 7.415], ["16400", 27.0943], ["16500", 44.8364]]}
[ { "code": "class Solution:\n def nextRow(self, preList: List[int]) -> List[int]:\n l = []\n # the new row contain one additional element\n for i in range(len(preList) + 1):\n if i == 0:\n l.append(1)\n elif i == len(preList):\n l.append...
48
[ { "code": "class Solution:\n def getRow(self, rowIndex: int) -> List[int]:\n row = [1]\n for i in range(rowIndex):\n next_row = [None] * (len(row) + 1)\n next_row[0] = 1\n next_row[-1] = 1\n for j in range(1, len(row)):\n next_row[j] = ...
9
120
triangle
<p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p> <p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th...
57.684166
Medium
[ "array", "dynamic-programming" ]
{"lang": "python3", "distribution": [["30", 0.0116], ["31", 0.0116], ["32", 0.0231], ["34", 0.0116], ["35", 0.0116], ["37", 0.0116], ["38", 0.0116], ["39", 0.0231], ["40", 0.0116], ["41", 0.0578], ["42", 0.0578], ["43", 0.104], ["44", 0.1272], ["45", 0.0809], ["46", 0.3815], ["47", 0.5548], ["48", 0.3815], ["49", 0.751...
{"lang": "python3", "distribution": [["17100", 0.0116], ["17200", 0.0462], ["17300", 0.1272], ["17400", 1.9651], ["17500", 12.2067], ["17600", 21.9397], ["17700", 16.0675], ["17800", 6.1727], ["17900", 8.1956], ["18000", 8.2534], ["18100", 3.6181], ["18200", 1.9767], ["18300", 0.6126], ["18400", 0.2659], ["18500", 0.48...
[ { "code": "def minimumTotal(tri: List[List[int]]) -> int:\n \n for i in range(len(tri)-2, -1, -1):\n \n for j in range(len(tri[i])):\n next = tri[i+1]\n\n tri[i][j] += min(next[j], next[j+1])\n return tri[0][0]\n\nwith open(\"user.out\", \"w\") as f:\n for case in...
68
[ { "code": "class Solution:\n def minimumTotal(self, triangle: List[List[int]]) -> int:\n n = len(triangle)\n dp = triangle[-1]\n for i in range(n-2, -1, -1):\n for j in range(i+1):\n dp[j] = min(dp[j], dp[j+1]) + triangle[i][j]\n return dp[0]\n ", ...
50
257
binary-tree-paths
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
64.694464
Easy
[ "string", "backtracking", "tree", "depth-first-search", "binary-tree" ]
{"lang": "python3", "distribution": [["15", 0.0462], ["16", 0.0308], ["18", 0.0308], ["19", 0.1385], ["20", 0.0924], ["21", 0.0616], ["22", 0.2155], ["23", 0.6773], ["24", 0.5542], ["25", 0.4464], ["26", 0.8159], ["27", 2.7248], ["28", 1.5856], ["29", 1.6164], ["30", 2.3861], ["31", 7.1429], ["32", 4.0486], ["33", 3.89...
{"lang": "python3", "distribution": [["16100", 0.0308], ["16200", 0.1078], ["16300", 1.2161], ["16400", 14.2703], ["16500", 32.0505], ["16600", 43.3344]]}
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:\n paths =...
47
[ { "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:\n ans = [...
10
258
add-digits
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
67.131203
Easy
[ "math", "simulation", "number-theory" ]
{"lang": "python3", "distribution": [["15", 0.0491], ["18", 0.0327], ["19", 0.1637], ["20", 0.1474], ["21", 0.0655], ["22", 0.262], ["23", 0.786], ["24", 0.8515], ["25", 0.4094], ["26", 1.2445], ["27", 1.8995], ["28", 2.8328], ["29", 1.8012], ["30", 2.3579], ["31", 5.3709], ["32", 5.4364], ["33", 4.9451], ["34", 5.0598...
{"lang": "python3", "distribution": [["15900", 0.0164], ["16000", 0.0327], ["16100", 0.0164], ["16200", 0.2947], ["16300", 4.4539], ["16400", 22.2368], ["16500", 42.7378]]}
[ { "code": "class Solution:\n def addDigits(self, num: int) -> int:\n if num == 0 : return 0\n if num % 9 == 0 : return 9\n else : return (num % 9) \n", "runtime": "15" }, { "code": "class Solution:\n def addDigits(self, num: int) -> int:\n if num == 0:\n ...
46
[ { "code": "class Solution:\n def addDigits(self, num: int) -> int:\n if num == 0:\n return 0\n elif num % 9 == 0:\n return 9\n else:\n return num % 9\n \n", "memory": "15900" }, { "code": "class Solution:\n def addDigits(self, num: i...
10
260
single-number-iii
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
70.77235
Medium
[ "array", "bit-manipulation" ]
{"lang": "python3", "distribution": [["49", 82.42369999999997], ["89", 0.6243999999999998], ["130", 0.1664], ["171", 0.2912], ["211", 0.0416], ["252", 0.0416], ["293", 0.0416], ["333", 0.0416], ["374", 0.0416], ["414", 0.0416], ["455", 0.1248], ["496", 1.1235999999999997], ["536", 0.1248], ["577", 0.0832], ["618", 0.04...
{"lang": "python3", "distribution": [["17500", 0.0416], ["18100", 0.4581], ["18200", 6.0392], ["18300", 21.3661], ["18400", 23.4486], ["18500", 6.289], ["18600", 1.6243], ["18700", 6.2474], ["18800", 16.4931], ["18900", 12.703]]}
[ { "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> List[int]:\n freq=Counter(nums)\n return [x for x,y in freq.items() if y==1]\n\nwith open(\"user.out\", \"w\") as f:\n inputs = map(loads, stdin)\n for nums in inputs:\n print(str(Solution().singleNumber(nums))...
103
[ { "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> List[int]:\n freq=Counter(nums)\n return [x for x,y in freq.items() if y==1]\n\nwith open(\"user.out\", \"w\") as f:\n inputs = map(loads, stdin)\n for nums in inputs:\n print(str(Solution().singleNumber(nums))...
18