4. Median of Two Sorted Arrays
Problem Link class Solution: def findMedianSortedArrays(self, A: List[int], B: List[int]) -> float: if len(A) > len(B): return self.findMedianSortedArrays(B, A) La, Lb = len(A), len(B) total = La + Lb h...
Search for a command to run...
Problem Link class Solution: def findMedianSortedArrays(self, A: List[int], B: List[int]) -> float: if len(A) > len(B): return self.findMedianSortedArrays(B, A) La, Lb = len(A), len(B) total = La + Lb h...
Problem Link class Solution: def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]: res = [] lower = max(0, k - len(nums2)) # pick all elements from nums2 upper = min(k, len(nums1)) # pick all elemen...
Problem Link Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. Example: Input: n = 32 Output: [1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24,25,26,27,28,29,3,30,31,32,4,5,6,7,8,9] class Solution: ...
Problem Link Given an integer array nums and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(nums[i] - nums[j]) <= t and abs(i - j) <= k. Solution Bucket size: t + 1 class Solution: def c...
Problem Link Let dpVer[i][j] := the number of continuous 1’s from grid[0][j-1] to grid[i-1][j-1] Let dpHor[i][j] := the number of continuous 1’s from grid[i-1][0] to grid[i-1][j-1] class Solution: def largest1BorderedSquare(self, grid: List[List[...
Problem Link dp[i][k] := largest average sum of nums[i:] with k partitions class Solution: def largestSumOfAverages(self, nums: List[int], k: int) -> float: L = len(nums) dp = [[0 for _ in range(k+1)] for _ in range(L)] # ...
Problem Link class Solution: def getPermutation(self, n: int, k: int) -> str: fact = [1] * (n+1) for i in range(2, n+1): fact[i] = fact[i-1] * i res = '' numGroups = n digits = '123456789' ...
Problem Link Solution 1: DFS class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: memo = dict() return self.helper(stones, 0, 0, 0, memo) def helper(self, stones, i, S1, S2, memo) -> int: if (i, S1, ...
Problem Link class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: left = 1 right = 2 * 10**9 while left < right: m = left + (right - left) // 2 cnt = self.count(a, b, c, m...