From 2e0aeb5d45aa6f9d0d7d8f1e0a0dc52c2f6fcd74 Mon Sep 17 00:00:00 2001 From: cassanof Date: Wed, 28 Jun 2023 07:24:50 -0700 Subject: [PATCH] cleaned up garbage --- ...104-path-in-zigzag-labelled-binary-tree.js | 0 ...intervals-into-minimum-number-of-groups.js | 0 ... 2407-longest-increasing-subsequence-ii.js | 0 ...y-tree.js => 993-cousins-in-binary-tree.js | 0 TBD-leftmost-column-with-at-least-a-one.js | 34 ----- tmp.js | 141 ------------------ 6 files changed, 175 deletions(-) rename 1104.path-in-zigzag-labelled-binary-tree.js => 1104-path-in-zigzag-labelled-binary-tree.js (100%) rename 2406.divide-intervals-into-minimum-number-of-groups.js => 2406-divide-intervals-into-minimum-number-of-groups.js (100%) rename 2407.longest-increasing-subsequence-ii.js => 2407-longest-increasing-subsequence-ii.js (100%) rename 993.cousins-in-binary-tree.js => 993-cousins-in-binary-tree.js (100%) delete mode 100644 TBD-leftmost-column-with-at-least-a-one.js delete mode 100644 tmp.js diff --git a/1104.path-in-zigzag-labelled-binary-tree.js b/1104-path-in-zigzag-labelled-binary-tree.js similarity index 100% rename from 1104.path-in-zigzag-labelled-binary-tree.js rename to 1104-path-in-zigzag-labelled-binary-tree.js diff --git a/2406.divide-intervals-into-minimum-number-of-groups.js b/2406-divide-intervals-into-minimum-number-of-groups.js similarity index 100% rename from 2406.divide-intervals-into-minimum-number-of-groups.js rename to 2406-divide-intervals-into-minimum-number-of-groups.js diff --git a/2407.longest-increasing-subsequence-ii.js b/2407-longest-increasing-subsequence-ii.js similarity index 100% rename from 2407.longest-increasing-subsequence-ii.js rename to 2407-longest-increasing-subsequence-ii.js diff --git a/993.cousins-in-binary-tree.js b/993-cousins-in-binary-tree.js similarity index 100% rename from 993.cousins-in-binary-tree.js rename to 993-cousins-in-binary-tree.js diff --git a/TBD-leftmost-column-with-at-least-a-one.js b/TBD-leftmost-column-with-at-least-a-one.js deleted file mode 100644 index bfd5e911..00000000 --- a/TBD-leftmost-column-with-at-least-a-one.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * // This is the BinaryMatrix's API interface. - * // You should not implement it, or speculate about its implementation - * function BinaryMatrix() { - * @param {integer} x, y - * @return {integer} - * this.get = function(x, y) { - * ... - * }; - * - * @return {[integer, integer]} - * this.dimensions = function() { - * ... - * }; - * }; - */ - -/** - * @param {BinaryMatrix} binaryMatrix - * @return {number} - */ -const leftMostColumnWithOne = function (binaryMatrix) { - const [rows, cols] = binaryMatrix.dimensions() - let candidate = -1 - for (let r = 0, c = cols - 1; r < rows && c >= 0; ) { - if (binaryMatrix.get(r, c) === 1) { - candidate = c - c-- - } else { - r++ - } - } - return candidate -} diff --git a/tmp.js b/tmp.js deleted file mode 100644 index 4e53563a..00000000 --- a/tmp.js +++ /dev/null @@ -1,141 +0,0 @@ -/** - * @param {string} s - * @return {boolean} - */ -var isDecomposable = function(s) { - let hasTwo = false - let i = 0 - let j = 0 - - while(j < s.length) { - while(j + 1 < s.length && s[j + 1] === s[i]) { - j += 1 - } - - if (((j - i + 1) % 3) === 2) { - if (!hasTwo) { - hasTwo = true - } else { - return false - } - } else if (((j - i + 1) % 3) === 1) { - return false - } - j++ - i = j - } - - return hasTwo -}; - - -class Solution { -public: - vector longestCommomSubsequence(vector>& arrays) { - int n = arrays.size(); - vector nums = vector(100); // 100 possible numbers as stated in the question - for (int i = 0; i < n; i++) { - for (int j = 0; j < arrays[i].size(); j++) { - nums[arrays[i][j] - 1]++; // count occurrences - } - } - vector ans; - for (int i = 0; i < 100; i++) { - if (nums[i] == n) ans.push_back(i + 1); // save it if it appears in every array - } - return ans; - } -}; - -class Solution { - public int[] findMaximums(int[] nums) { - if(nums == null || nums.length == 0) return nums; - // calc the [l, r] for each ele where in [l, r]: ele is the min value - int len = nums.length; - TreeSet idx = new TreeSet<>(); - Integer[] indices = new Integer[len]; - for(int i = 0; i < len; i++) indices[i] = i; - Arrays.sort(indices, (l, r) -> nums[l] - nums[r]); - int prev = -1; - int[] ranges = new int[len]; - Queue sameLevel = new LinkedList<>(); - int[] ans = new int[len]; - for(int i = 0; i < len; i++) { - if(nums[indices[i]] > prev) { - while(!sameLevel.isEmpty()) { - idx.add(sameLevel.poll()); - } - } - Integer l = idx.lower(indices[i]); - Integer r = idx.higher(indices[i]); - ranges[indices[i]] = (r == null?len - 1:r - 1) - (l == null?0:l + 1) + 1; - prev = nums[indices[i]]; - sameLevel.add(indices[i]); - } - // we iterate ranges from maximum to minimum to construct the ans array - int j = len - 1; - for(int i = len - 1; i >= 0; i--) { - while(j >= 0 && ranges[indices[j]] < len - i) { - j--; - } - ans[len - 1 - i] = nums[indices[j]]; - } - return ans; - } -} - -class Solution: - def minDayskVariants(self, points: List[List[int]], k: int) -> int: - lo = 0 - hi = int(1e9) - - # binary search check helper function - def check(day): - lines = collections.defaultdict(collections.Counter) - - # 2d sweep line - for x, y in points: - lbx, lby = (x, y - day) # left point - ubx, uby = (x - day, y) # bottom point - - # lbx + lby == ubx + uby == new x axis's open line - lines[lbx+lby][lby-lbx] += 1 - lines[ubx+uby][uby-ubx+1] -= 1 # - - # lbx + lby == ubx + uby == new x axis's close line - lbx, lby = (x + day, y) # right point - ubx, uby = (x, y + day) # upper point - lines[lbx+lby+1][lby-lbx] -= 1 - lines[ubx+uby+1][uby-ubx+1] += 1 - - # hold a new ranges to sweep all lines from left to right on new x axis - ranges = collections.Counter() - - # for every critical points on new x axis (it's a diag on the original axis), - # add the sweep lines on new y axis - for diag in sorted(lines): - for num in sorted(lines[diag]): - cnt = lines[diag][num] - ranges[num] += cnt - - # for every critical points, check whether there is an area having - # overlapping points >= k - cur = 0 - for num in sorted(ranges): - cnt = ranges[num] - cur += cnt - - if cur >= k: - return True - - return False - - # binary search - while lo < hi: - mid = (lo + hi) // 2 - if check(mid): - hi = mid - else: - lo = mid + 1 - - return lo