diff --git a/.gitignore b/.gitignore index 4854d5a7..7be6a7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .env .env.* *.local +.DS_Store dist-newstyle/ .stack-work/ diff --git a/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/manifest.yaml b/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/manifest.yaml new file mode 100644 index 00000000..4e889d2e --- /dev/null +++ b/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/manifest.yaml @@ -0,0 +1,307 @@ +entry: + id: 2025 + title: "maximum-number-of-ways-to-partition-an-array" + params: + nums: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().waysToPartition({nums}, {k})" + rust: "Solution::ways_to_partition({nums}, {k})" + python3: "Solution().waysToPartition({nums}, {k})" + python2: "Solution().waysToPartition({nums}, {k})" + ruby: "ways_to_partition({nums}, {k})" + java: "new Solution().waysToPartition({nums}, {k})" + csharp: "new Solution().WaysToPartition({nums}, {k})" + kotlin: "Solution().waysToPartition({nums}, {k})" + go: "waysToPartition({nums}, {k})" + dart: "Solution().waysToPartition({nums}, {k})" + swift: "Solution().waysToPartition({nums}, {k})" + typescript: "waysToPartition({nums}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().waysToPartition(nums, k, {result})" + checker: | + class Checker: + def waysToPartition(self, nums, k, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + from collections import Counter + total = sum(nums) + right = Counter() + left = Counter() + running = 0 + for value in nums[:-1]: + running += value + right[2 * running - total] += 1 + expected = right[0] + running = 0 + for value in nums: + running += value + delta = k - value + expected = max(expected, left[delta] + right[-delta]) + pivot_delta = 2 * running - total + left[pivot_delta] += 1 + right[pivot_delta] -= 1 + return result == expected + +seed: 20250826 + +tests: + - name: "example_one" + in: + nums: [2, -1, 2] + k: 3 + out: 1 + - name: "example_two" + in: + nums: [0, 0, 0] + k: 1 + out: 2 + - name: "example_three" + in: + nums: [22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14] + k: -33 + out: 4 + - name: "two_elements_equal" + in: + nums: [5, 5] + k: 9 + out: 1 + - name: "two_elements_unequal" + in: + nums: [5, 4] + k: 9 + out: 0 + - name: "two_elements_no_help" + in: + nums: [5, 4] + k: -2 + out: 0 + - name: "all_negative_zero_sum" + in: + nums: [-1, -1, -1, -1] + k: 7 + out: 1 + - name: "alternating_zeroes" + in: + nums: [1, -1, 1, -1, 1, -1] + k: 0 + out: 2 + - name: "single_balanced_pivot" + in: + nums: [3, 1, 2] + k: 10 + out: 1 + - name: "change_creates_balance" + in: + nums: [1, 2, 4] + k: 3 + out: 1 + - name: "multiple_existing" + in: + nums: [0, 0, 1, -1, 0, 0] + k: 8 + out: 4 + - name: "negative_k" + in: + nums: [4, -2, -2, 0] + k: -4 + out: 1 + - name: "large_values_cancel" + in: + nums: [100000, -100000, 100000, -100000] + k: 100000 + out: 2 + - name: "large_values_unbalanced" + in: + nums: [100000, 100000, -100000, -99999] + k: -100000 + out: 0 + - name: "pivot_at_first" + in: + nums: [7, 1, 2, 4] + k: 3 + out: 1 + - name: "pivot_at_last" + in: + nums: [1, 2, 4, 7] + k: 7 + out: 1 + - name: "no_partition" + in: + nums: [1, 1, 1, 1, 1] + k: 100 + out: 0 + - name: "constant_positive" + in: + nums: [2, 2, 2, 2, 2, 2] + k: -3 + out: 1 + - name: "constant_zero_replacement" + in: + nums: [0, 0, 0, 0, 0] + k: 0 + out: 4 + - name: "mixed_signs" + in: + nums: [-5, 3, 2, -1, 1] + k: 4 + out: 1 + - name: "replacement_is_existing_value" + in: + nums: [2, 1, 1, 2] + k: 1 + out: 1 + - name: "odd_length_symmetry" + in: + nums: [3, -1, -2, 4, -4, 0, 0] + k: 5 + out: 3 + - name: "all_maximum" + in: + nums: [100000, 100000, 100000, 100000] + k: -100000 + out: 2 + - name: "all_minimum" + in: + nums: [-100000, -100000, -100000, -100000] + k: 100000 + out: 2 + - name: "prefix_sum_repeated" + in: + nums: [1, -1, 2, -2, 3, -3, 4, -4] + k: 6 + out: 3 + - name: "unequal_total" + in: + nums: [8, -3, 5, 2, -1] + k: -6 + out: 0 + - name: "four_zeroes_with_outlier" + in: + nums: [0, 0, 0, 5, 0, 0] + k: 0 + out: 5 + - name: "negative_outlier" + in: + nums: [0, 0, 0, -5, 0, 0] + k: 0 + out: 5 + - name: "balanced_after_middle_change" + in: + nums: [5, 1, 1, 1, 1] + k: -1 + out: 0 + - name: "single_existing_balance" + in: + nums: [4, 2, 2, 4] + k: 9 + out: 1 + - name: "large_magnitude_mix" + in: + nums: [-100000, 1, 99999, 100000, -1] + k: 0 + out: 0 + - name: "generated_small_general" + seed: 101 + in: + nums: + gen: "array" + len: + gen: "int" + min: 2 + max: 25 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + k: + gen: "int" + min: -100000 + max: 100000 + - name: "generated_small_duplicates" + seed: 202 + in: + nums: + gen: "array" + len: + gen: "int" + min: 10 + max: 40 + of: + gen: "int" + min: -3 + max: 3 + distinct: false + sorted: false + elemType: "int" + k: 2 + - name: "generated_medium_signed" + seed: 303 + in: + nums: + gen: "array" + len: + gen: "int" + min: 500 + max: 1500 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + k: + gen: "int" + min: -100000 + max: 100000 + - name: "generated_large_bounded" + seed: 404 + in: + nums: + gen: "array" + len: 80000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + k: + gen: "int" + min: -100000 + max: 100000 + - name: "generated_maximum_size" + seed: 505 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + k: + gen: "int" + min: -100000 + max: 100000 diff --git a/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/sol.py b/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/sol.py new file mode 100644 index 00000000..43a3b9dd --- /dev/null +++ b/tests/2001-2500/2025. maximum-number-of-ways-to-partition-an-array/sol.py @@ -0,0 +1,27 @@ +class Solution: + def waysToPartition(self, nums, k): + n = len(nums) + + total = sum(nums) + + ans, running_sum = 0, 0 + + R, L = defaultdict(int), defaultdict(int) + + for i in range(n-1): + running_sum += nums[i] + R[running_sum-(total-running_sum)] += 1 + + + ans = R[0] + + running_sum = 0 + + for i in range(n): + running_sum += nums[i] + d = k-nums[i] + ans = max(ans,L[d]+R[-d]) + L[running_sum-(total-running_sum)] += 1 + R[running_sum-(total-running_sum)] -= 1 + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2027. minimum-moves-to-convert-string/manifest.yaml b/tests/2001-2500/2027. minimum-moves-to-convert-string/manifest.yaml new file mode 100644 index 00000000..cd879cfd --- /dev/null +++ b/tests/2001-2500/2027. minimum-moves-to-convert-string/manifest.yaml @@ -0,0 +1,225 @@ +entry: + id: 2027 + title: "minimum-moves-to-convert-string" + params: + s: + type: string + call: + cpp: "Solution().minimumMoves({s})" + rust: "Solution::minimum_moves({s})" + python3: "Solution().minimumMoves({s})" + python2: "Solution().minimumMoves({s})" + ruby: "minimum_moves({s})" + java: "new Solution().minimumMoves({s})" + csharp: "new Solution().MinimumMoves({s})" + kotlin: "Solution().minimumMoves({s})" + go: "minimumMoves({s})" + dart: "Solution().minimumMoves({s})" + swift: "Solution().minimumMoves({s})" + typescript: "minimumMoves({s})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumMoves(s, {result})" + checker: | + class Checker: + def minimumMoves(self, s, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + expected = 0 + i = 0 + while i < len(s): + if s[i] == 'X': + expected += 1 + i += 3 + else: + i += 1 + return result == expected + +seed: 2027 + +tests: + - name: "example_xxx" + in: + s: "XXX" + out: 1 + - name: "example_xxox" + in: + s: "XXOX" + out: 2 + - name: "example_all_o" + in: + s: "OOOO" + out: 0 + - name: "minimum_length_all_x" + in: + s: "XXXX" + out: 2 + - name: "minimum_length_one_x" + in: + s: "OOOX" + out: 1 + - name: "leading_x" + in: + s: "XOOO" + out: 1 + - name: "trailing_x" + in: + s: "OOOX" + out: 1 + - name: "single_x_middle" + in: + s: "OOXOO" + out: 1 + - name: "two_separated_x" + in: + s: "XOXO" + out: 1 + - name: "two_far_x" + in: + s: "XOOOX" + out: 2 + - name: "exact_block_boundary" + in: + s: "XXXOOOXXX" + out: 2 + - name: "overlapping_x_run_four" + in: + s: "XXXXO" + out: 2 + - name: "overlapping_x_run_five" + in: + s: "XXXXX" + out: 2 + - name: "overlapping_x_run_six" + in: + s: "XXXXXX" + out: 2 + - name: "overlapping_x_run_seven" + in: + s: "XXXXXXX" + out: 3 + - name: "alternating_start_x" + in: + s: "XOXOXOXO" + out: 2 + - name: "alternating_start_o" + in: + s: "OXOXOXOX" + out: 2 + - name: "only_first_three_x" + in: + s: "XXXOOOOOO" + out: 1 + - name: "only_last_three_x" + in: + s: "OOOOOOXXX" + out: 1 + - name: "x_runs_with_separator" + in: + s: "XXXOXXXOXXX" + out: 3 + - name: "short_mixed_one" + in: + s: "OXOOXXO" + out: 2 + - name: "short_mixed_two" + in: + s: "XXOOXOOX" + out: 3 + - name: "short_mixed_three" + in: + s: "OXOXOXX" + out: 2 + - name: "short_mixed_four" + in: + s: "XOOXXOOXX" + out: 3 + - name: "long_run_with_gap" + in: + s: "XXXXXXXXXXOXXXXXXXXXX" + out: 7 + - name: "mostly_o_singletons" + in: + s: "OXOOOXOOOXOOO" + out: 3 + - name: "dense_mixed" + in: + s: "XXOXXOXXOXXO" + out: 4 + - name: "boundary_x_after_skip" + in: + s: "OXXXOXX" + out: 2 + - name: "boundary_x_before_skip" + in: + s: "XXOXOOO" + out: 2 + - name: "all_o_length_100" + in: + s: "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" + out: 0 + - name: "all_x_length_100" + in: + s: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + out: 34 + - name: "periodic_xxo_length_30" + in: + s: "XXOXXOXXOXXOXXOXXOXXOXXOXXOXXO" + out: 10 + - name: "periodic_oxx_length_30" + in: + s: "OXXOXXOXXOXXOXXOXXOXXOXXOXXOXXO" + out: 10 + - name: "alternating_length_31" + in: + s: "XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX" + out: 8 + - name: "generated_small_random" + seed: 11 + in: + s: + gen: "str" + len: + gen: "int" + min: 3 + max: 30 + alphabet: "XO" + - name: "generated_medium_random" + seed: 22 + in: + s: + gen: "str" + len: + gen: "int" + min: 100 + max: 300 + alphabet: "XO" + - name: "generated_x_heavy" + seed: 33 + in: + s: + gen: "str" + len: 1000 + alphabet: "XXXXO" + - name: "generated_o_heavy" + seed: 44 + in: + s: + gen: "str" + len: 1000 + alphabet: "OOOOX" + - name: "generated_max_random" + seed: 55 + in: + s: + gen: "str" + len: 1000 + alphabet: "XO" diff --git a/tests/2001-2500/2027. minimum-moves-to-convert-string/sol.py b/tests/2001-2500/2027. minimum-moves-to-convert-string/sol.py new file mode 100644 index 00000000..9b75f0b4 --- /dev/null +++ b/tests/2001-2500/2027. minimum-moves-to-convert-string/sol.py @@ -0,0 +1,10 @@ +class Solution: + def minimumMoves(self, s: str) -> int: + count = i = 0 + while i < len(s): + if s[i] == 'X': + count += 1 + i += 3 + else: + i += 1 + return count \ No newline at end of file diff --git a/tests/2001-2500/2028. find-missing-observations/manifest.yaml b/tests/2001-2500/2028. find-missing-observations/manifest.yaml new file mode 100644 index 00000000..bf58e985 --- /dev/null +++ b/tests/2001-2500/2028. find-missing-observations/manifest.yaml @@ -0,0 +1,326 @@ +entry: + id: 2028 + title: "find-missing-observations" + params: + rolls: + type: array + items: + type: int + mean: + type: int + n: + type: int + call: + cpp: "Solution().missingRolls({rolls}, {mean}, {n})" + rust: "Solution::missing_rolls({rolls}, {mean}, {n})" + python3: "Solution().missingRolls({rolls}, {mean}, {n})" + python2: "Solution().missingRolls({rolls}, {mean}, {n})" + ruby: "missing_rolls({rolls}, {mean}, {n})" + java: "new Solution().missingRolls({rolls}, {mean}, {n})" + csharp: "new Solution().MissingRolls({rolls}, {mean}, {n})" + kotlin: "Solution().missingRolls({rolls}, {mean}, {n})" + go: "missingRolls({rolls}, {mean}, {n})" + dart: "Solution().missingRolls({rolls}, {mean}, {n})" + swift: "Solution().missingRolls({rolls}, {mean}, {n})" + typescript: "missingRolls({rolls}, {mean}, {n})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().missingRolls(rolls, mean, n, {result})" + checker: | + class Checker: + def missingRolls(self, rolls, mean, n, result): + if not isinstance(result, list): + return False + target = mean * (len(rolls) + n) - sum(rolls) + if target < n or target > 6 * n: + return result == [] + return (len(result) == n and + all(isinstance(x, int) and 1 <= x <= 6 for x in result) and + sum(result) == target) + +seed: 2028 + +tests: + - name: "example_1" + in: + rolls: [3, 2, 4, 3] + mean: 4 + n: 2 + - name: "example_2" + in: + rolls: [1, 5, 6] + mean: 3 + n: 4 + - name: "example_3_impossible_high" + in: + rolls: [1, 2, 3, 4] + mean: 6 + n: 4 + out: [] + - name: "one_missing_minimum" + in: + rolls: [1] + mean: 1 + n: 1 + - name: "one_missing_maximum" + in: + rolls: [6] + mean: 6 + n: 1 + - name: "all_ones" + in: + rolls: [1, 1, 1, 1] + mean: 1 + n: 3 + - name: "all_sixes" + in: + rolls: [6, 6, 6] + mean: 6 + n: 5 + - name: "single_exact_face" + in: + rolls: [4] + mean: 4 + n: 1 + - name: "remainder_distribution" + in: + rolls: [2, 2, 2] + mean: 4 + n: 3 + - name: "mean_below_observations" + in: + rolls: [6, 6, 5] + mean: 2 + n: 4 + - name: "mean_above_observations" + in: + rolls: [1, 1, 2] + mean: 5 + n: 4 + - name: "impossible_low" + in: + rolls: [6, 6] + mean: 1 + n: 1 + out: [] + - name: "impossible_high" + in: + rolls: [1, 1] + mean: 6 + n: 1 + out: [] + - name: "diverse_small" + in: + rolls: [1, 3, 5, 6, 2] + mean: 4 + n: 2 + - name: "many_missing" + in: + rolls: [3, 4] + mean: 3 + n: 10 + - name: "n_one_fractional_target" + in: + rolls: [1, 2, 4] + mean: 3 + n: 1 + - name: "balanced_pair" + in: + rolls: [3, 3, 3, 3] + mean: 3 + n: 2 + - name: "low_mean_mixed" + in: + rolls: [1, 2, 6, 1] + mean: 2 + n: 5 + - name: "high_mean_mixed" + in: + rolls: [1, 6, 5, 6] + mean: 5 + n: 5 + - name: "large_n_min_feasible" + in: + rolls: [1, 1, 1, 1, 1] + mean: 2 + n: 20 + - name: "large_n_max_feasible" + in: + rolls: [6, 6, 6, 6, 6] + mean: 5 + n: 20 + - name: "gen_small_faces" + seed: 2101 + in: + rolls: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: 1 + max: 6 + mean: + gen: "int" + min: 1 + max: 6 + n: + gen: "int" + min: 1 + max: 20 + - name: "gen_medium_faces" + seed: 2102 + in: + rolls: + gen: "array" + len: + gen: "int" + min: 50 + max: 200 + of: + gen: "int" + min: 1 + max: 6 + mean: + gen: "int" + min: 1 + max: 6 + n: + gen: "int" + min: 1 + max: 200 + - name: "gen_large_observations" + seed: 2103 + in: + rolls: + gen: "array" + len: + gen: "int" + min: 80000 + max: 100000 + of: + gen: "int" + min: 1 + max: 6 + mean: + gen: "int" + min: 1 + max: 6 + n: 1 + - name: "gen_large_missing" + seed: 2104 + in: + rolls: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: 1 + max: 6 + mean: + gen: "int" + min: 1 + max: 6 + n: + gen: "int" + min: 80000 + max: 100000 + - name: "gen_maximum_both" + seed: 2105 + in: + rolls: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 6 + mean: 3 + n: 100000 + - name: "gen_single_roll" + seed: 2106 + in: + rolls: + gen: "array" + len: 1 + of: + gen: "int" + min: 1 + max: 6 + mean: + gen: "int" + min: 1 + max: 6 + n: 1 + - name: "six_observations_target" + in: + rolls: [6, 1, 6, 1, 6, 1] + mean: 4 + n: 6 + - name: "odd_remainder" + in: + rolls: [2, 4, 4, 2, 3] + mean: 3 + n: 4 + - name: "near_upper_limit" + in: + rolls: [1, 1, 1, 1, 1, 1, 1] + mean: 6 + n: 2 + out: [] + - name: "near_lower_limit" + in: + rolls: [6, 6, 6, 6, 6, 6, 6] + mean: 1 + n: 2 + out: [] + - name: "zero_surplus_impossible" + in: + rolls: [1, 1, 1] + mean: 1 + n: 2 + - name: "uniform_four" + in: + rolls: [4, 4, 4, 4, 4, 4] + mean: 4 + n: 6 + - name: "mixed_boundary_faces" + in: + rolls: [1, 6, 1, 6, 2, 5] + mean: 3 + n: 7 + - name: "high_n_low_sum_impossible" + in: + rolls: [6, 6, 6, 6] + mean: 2 + n: 2 + out: [] + - name: "high_n_high_sum_impossible" + in: + rolls: [1, 1, 1, 1] + mean: 5 + n: 2 + out: [] + - name: "exact_total_one" + in: + rolls: [1, 1, 1, 1, 1] + mean: 1 + n: 1 + - name: "exact_total_six" + in: + rolls: [6, 6, 6, 6, 6] + mean: 6 + n: 1 diff --git a/tests/2001-2500/2028. find-missing-observations/sol.py b/tests/2001-2500/2028. find-missing-observations/sol.py new file mode 100644 index 00000000..83c35a8e --- /dev/null +++ b/tests/2001-2500/2028. find-missing-observations/sol.py @@ -0,0 +1,10 @@ +class Solution: + def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]: + m = len(rolls) + missing_sum = mean * (m + n) - sum(rolls) + res = [0] * n + while missing_sum >= n: + res = [res[0]+1]*n + missing_sum -= n + for i in range(missing_sum): res[i] += 1 + return [] if res[0] > 6 or 0 in res else res \ No newline at end of file diff --git a/tests/2001-2500/2029. stone-game-ix/manifest.yaml b/tests/2001-2500/2029. stone-game-ix/manifest.yaml new file mode 100644 index 00000000..7c607a3e --- /dev/null +++ b/tests/2001-2500/2029. stone-game-ix/manifest.yaml @@ -0,0 +1,244 @@ +entry: + id: 2029 + title: "stone-game-ix" + params: + stones: + type: array + items: + type: int + call: + cpp: "Solution().stoneGameIX({stones})" + rust: "Solution::stone_game_ix({stones})" + python3: "Solution().stoneGameIX({stones})" + python2: "Solution().stoneGameIX({stones})" + ruby: "stone_game_ix({stones})" + java: "new Solution().stoneGameIX({stones})" + csharp: "new Solution().StoneGameIX({stones})" + kotlin: "Solution().stoneGameIX({stones})" + go: "stoneGameIX({stones})" + dart: "Solution().stoneGameIX({stones})" + swift: "Solution().stoneGameIX({stones})" + typescript: "stoneGameIX({stones})" + +judge: + type: "exact" + +limits: + time_ms: 300 + memory_mb: 300 + +oracle: + python3: + call: "Checker().stoneGameIX(stones, {result})" + checker: | + class Checker: + def stoneGameIX(self, stones, result): + if not isinstance(result, bool) or not isinstance(stones, list): + return False + counts = [0, 0, 0] + for value in stones: + if not isinstance(value, int) or isinstance(value, bool) or value < 1 or value > 10000: + return False + counts[value % 3] += 1 + expected = (abs(counts[1] - counts[2]) >= 3 + if counts[0] % 2 + else min(counts[1], counts[2]) >= 1) + return result is expected + +seed: 20292029 + +tests: + - name: "example_1" + in: + stones: [2, 1] + out: true + - name: "example_2" + in: + stones: [2] + out: false + - name: "example_3" + in: + stones: [5, 1, 2, 4, 3] + out: false + - name: "single_residue_zero" + in: + stones: [3] + out: false + - name: "single_residue_one" + in: + stones: [1] + out: false + - name: "two_matching_one_residues" + in: + stones: [1, 4] + out: false + - name: "one_of_each_nonzero" + in: + stones: [1, 2] + out: true + - name: "zero_even_with_both" + in: + stones: [3, 1, 2] + out: false + - name: "zero_odd_difference_two" + in: + stones: [3, 1, 4, 2] + out: false + - name: "zero_odd_difference_three" + in: + stones: [3, 1, 4, 7, 2] + out: false + - name: "zero_odd_difference_four" + in: + stones: [6, 1, 4, 7, 10, 2] + out: true + - name: "all_zero_even" + in: + stones: [3, 6, 9, 12] + out: false + - name: "all_zero_odd" + in: + stones: [3, 6, 9] + out: false + - name: "all_ones" + in: + stones: [1, 1, 1, 1, 1] + out: false + - name: "all_twos" + in: + stones: [2, 2, 2, 2, 2] + out: false + - name: "balanced_nonzero_even_zero" + in: + stones: [6, 1, 4, 2, 5, 8] + out: false + - name: "balanced_nonzero_odd_zero" + in: + stones: [3, 1, 2, 4, 5] + out: false + - name: "large_values_residue_one" + in: + stones: [10000, 9997, 9994] + out: false + - name: "large_values_mixed" + in: + stones: [10000, 9999, 9998, 9997, 9996, 9995] + out: true + - name: "permuted_order" + in: + stones: [8, 3, 5, 1, 6, 4, 2, 7] + out: true + - name: "many_zero_balanced" + in: + stones: [3, 6, 12, 15, 1, 2, 4, 5] + out: true + - name: "many_zero_unbalanced" + in: + stones: [3, 6, 9, 1, 4, 7, 2] + out: false + - name: "one_zero_one_each" + in: + stones: [300, 10000, 9998] + out: false + - name: "two_zero_one_each" + in: + stones: [3, 6, 1, 2] + out: true + - name: "two_zero_only_one_side" + in: + stones: [3, 6, 1, 4] + out: false + - name: "odd_zero_equal_counts" + in: + stones: [300, 1, 4, 2, 5] + out: false + - name: "odd_zero_diff_boundary" + in: + stones: [9999, 1, 4, 7, 2, 5] + out: false + - name: "alternating_residues" + in: + stones: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: false + - name: "residue_pattern_false" + in: + stones: [1, 4, 7, 2, 3, 6] + out: true + - name: "residue_pattern_true" + in: + stones: [1, 4, 7, 10, 2, 3, 6, 9] + out: true + - name: "generated_small_uniform" + seed: 101 + in: + stones: + gen: "array" + len: + gen: "int" + min: 1 + max: 25 + of: + gen: "int" + min: 1 + max: 10000 + distinct: false + sorted: false + elemType: "int" + - name: "generated_small_duplicates" + seed: 202 + in: + stones: + gen: "array" + len: + gen: "int" + min: 10 + max: 60 + of: + gen: "int" + min: 3 + max: 12 + distinct: false + sorted: false + elemType: "int" + - name: "generated_medium" + seed: 303 + in: + stones: + gen: "array" + len: + gen: "int" + min: 500 + max: 1500 + of: + gen: "int" + min: 1 + max: 10000 + distinct: false + sorted: false + elemType: "int" + - name: "generated_near_limit_a" + seed: 404 + in: + stones: + gen: "array" + len: 99999 + of: + gen: "int" + min: 1 + max: 10000 + distinct: false + sorted: false + elemType: "int" + - name: "generated_near_limit_b" + seed: 505 + in: + stones: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 10000 + distinct: false + sorted: false + elemType: "int" diff --git a/tests/2001-2500/2029. stone-game-ix/sol.py b/tests/2001-2500/2029. stone-game-ix/sol.py new file mode 100644 index 00000000..bb2a5df0 --- /dev/null +++ b/tests/2001-2500/2029. stone-game-ix/sol.py @@ -0,0 +1,11 @@ +class Solution: + def stoneGameIX(self, stones: List[int]) -> bool: + f = [0, 0, 0] + + for s in stones: + f[s % 3] += 1 + + if f[0] & 1: + return abs(f[1] - f[2]) >= 3 + + return min(f[1], f[2]) >= 1 \ No newline at end of file diff --git a/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/manifest.yaml b/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/manifest.yaml new file mode 100644 index 00000000..679f836b --- /dev/null +++ b/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/manifest.yaml @@ -0,0 +1,356 @@ +entry: + id: 2030 + title: "smallest-k-length-subsequence-with-occurrences-of-a-letter" + params: + s: + type: string + k: + type: int + letter: + type: string + repetition: + type: int + call: + cpp: "Solution().smallestSubsequence({s}, {k}, {letter}[0], {repetition})" + rust: "Solution::smallest_subsequence({s}, {k}, {letter}[0], {repetition})" + python3: "Solution().smallestSubsequence({s}, {k}, {letter}, {repetition})" + python2: "Solution().smallestSubsequence({s}, {k}, {letter}, {repetition})" + ruby: "smallest_subsequence({s}, {k}, {letter}, {repetition})" + java: "new Solution().smallestSubsequence({s}, {k}, {letter}.charAt(0), {repetition})" + csharp: "new Solution().SmallestSubsequence({s}, {k}, {letter}[0], {repetition})" + kotlin: "Solution().smallestSubsequence({s}, {k}, {letter}[0], {repetition})" + go: "smallestSubsequence({s}, {k}, {letter}[0], {repetition})" + dart: "Solution().smallestSubsequence({s}, {k}, {letter}, {repetition})" + swift: "Solution().smallestSubsequence({s}, {k}, {letter}.first!, {repetition})" + typescript: "smallestSubsequence({s}, {k}, {letter}, {repetition})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().check(s, k, letter, repetition, {result})" + checker: | + class Checker: + def check(self, s, k, letter, repetition, result): + stack = [] + need = repetition + remaining = s.count(letter) + for i, ch in enumerate(s): + if ch == letter: + remaining -= 1 + while stack and stack[-1] > ch and len(stack) + len(s) - i - 1 >= k: + if stack[-1] == letter and remaining < need: + break + if stack.pop() == letter: + need += 1 + if len(stack) < k: + if ch == letter: + stack.append(ch) + need -= 1 + elif k - len(stack) > need: + stack.append(ch) + return isinstance(result, str) and result == ''.join(stack) + +seed: 20302030 + +tests: + - name: "example_1_leet" + in: + s: "leet" + k: 3 + letter: "e" + repetition: 1 + out: "eet" + - name: "example_2_leetcode" + in: + s: "leetcode" + k: 4 + letter: "e" + repetition: 2 + out: "ecde" + - name: "example_3_all_required" + in: + s: "bb" + k: 2 + letter: "b" + repetition: 2 + out: "bb" + - name: "single_a" + in: + s: "a" + k: 1 + letter: "a" + repetition: 1 + out: "a" + - name: "single_z" + in: + s: "z" + k: 1 + letter: "z" + repetition: 1 + out: "z" + - name: "prefix_required" + in: + s: "abc" + k: 2 + letter: "a" + repetition: 1 + out: "ab" + - name: "late_required" + in: + s: "cba" + k: 2 + letter: "a" + repetition: 1 + out: "ba" + - name: "z_before_a" + in: + s: "zzza" + k: 2 + letter: "z" + repetition: 1 + out: "za" + - name: "many_a_after_b" + in: + s: "baaa" + k: 2 + letter: "a" + repetition: 1 + out: "aa" + - name: "interleaved_z" + in: + s: "azbz" + k: 3 + letter: "z" + repetition: 1 + out: "abz" + - name: "alternating_b" + in: + s: "abab" + k: 3 + letter: "b" + repetition: 1 + out: "aab" + - name: "descending_c" + in: + s: "dcba" + k: 3 + letter: "c" + repetition: 1 + out: "cba" + - name: "all_a_partial" + in: + s: "aaaaa" + k: 3 + letter: "a" + repetition: 2 + out: "aaa" + - name: "required_at_end" + in: + s: "abcde" + k: 4 + letter: "e" + repetition: 1 + out: "abce" + - name: "descending_first_required" + in: + s: "edcba" + k: 3 + letter: "e" + repetition: 1 + out: "eba" + - name: "two_a_required" + in: + s: "bacbac" + k: 4 + letter: "a" + repetition: 2 + out: "abac" + - name: "middle_b_required" + in: + s: "cbacba" + k: 4 + letter: "b" + repetition: 1 + out: "acba" + - name: "x_prefix" + in: + s: "xyza" + k: 3 + letter: "a" + repetition: 1 + out: "xya" + - name: "two_z_required" + in: + s: "azzzb" + k: 3 + letter: "z" + repetition: 2 + out: "azz" + - name: "three_a_available" + in: + s: "cabaa" + k: 3 + letter: "a" + repetition: 2 + out: "aaa" + - name: "qwerty_e" + in: + s: "qwerty" + k: 3 + letter: "e" + repetition: 1 + out: "ert" + - name: "p_in_order" + in: + s: "mnopqr" + k: 5 + letter: "p" + repetition: 1 + out: "mnopq" + - name: "duplicate_blocks" + in: + s: "aabbcc" + k: 4 + letter: "b" + repetition: 1 + out: "aabb" + - name: "a_suffix" + in: + s: "bbacaa" + k: 4 + letter: "a" + repetition: 2 + out: "acaa" + - name: "z_prefix" + in: + s: "zzabc" + k: 3 + letter: "z" + repetition: 1 + out: "zab" + - name: "a_cluster" + in: + s: "caaab" + k: 3 + letter: "a" + repetition: 2 + out: "aaa" + - name: "alternating_c" + in: + s: "bcbcbc" + k: 4 + letter: "c" + repetition: 2 + out: "bbcc" + - name: "a_middle_twice" + in: + s: "dabbad" + k: 4 + letter: "a" + repetition: 2 + out: "abad" + - name: "b_suffix_required" + in: + s: "aaaabbbb" + k: 5 + letter: "b" + repetition: 2 + out: "aaabb" + - name: "a_tail_required" + in: + s: "cbbaaa" + k: 4 + letter: "a" + repetition: 2 + out: "baaa" + - name: "two_z_alternating" + in: + s: "azazaz" + k: 4 + letter: "z" + repetition: 2 + out: "aazz" + - name: "f_at_start" + in: + s: "fedcba" + k: 2 + letter: "f" + repetition: 1 + out: "fa" + - name: "full_leetcode" + in: + s: "leetcode" + k: 8 + letter: "e" + repetition: 3 + out: "leetcode" + - name: "repeated_abc" + in: + s: "abcabcabc" + k: 5 + letter: "c" + repetition: 1 + out: "aaabc" + - name: "z_block" + in: + s: "zzzzabc" + k: 6 + letter: "z" + repetition: 3 + out: "zzzabc" + - name: "generated_all_a_small" + seed: 20301 + in: + s: + gen: "str" + len: 50 + alphabet: "a" + k: 37 + letter: "a" + repetition: 12 + - name: "generated_all_b_medium" + seed: 20302 + in: + s: + gen: "str" + len: 1000 + alphabet: "b" + k: 777 + letter: "b" + repetition: 400 + - name: "generated_all_c_large" + seed: 20303 + in: + s: + gen: "str" + len: 50000 + alphabet: "c" + k: 49999 + letter: "c" + repetition: 25000 + - name: "generated_all_d_max" + seed: 20304 + in: + s: + gen: "str" + len: 50000 + alphabet: "d" + k: 25001 + letter: "d" + repetition: 1 + - name: "generated_all_e_tail" + seed: 20305 + in: + s: + gen: "str" + len: 20000 + alphabet: "e" + k: 19999 + letter: "e" + repetition: 19999 diff --git a/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/sol.py b/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/sol.py new file mode 100644 index 00000000..4cd9a269 --- /dev/null +++ b/tests/2001-2500/2030. smallest-k-length-subsequence-with-occurrences-of-a-letter/sol.py @@ -0,0 +1,20 @@ +class Solution: + def smallestSubsequence(self, s: str, k: int, letter: str, repetition: int) -> str: + counts,total = 0, 0 + n = len(s) + for ch in s: + if ch==letter: + total +=1 + stack = [] + occ = 0 + for idx,ch in enumerate(s): + if ch==letter: + counts +=1 + while stack and stack[-1]>ch and len(stack)+ (n-1-idx)>=k and (occ+total-counts-(stack[-1]==letter)+(ch==letter)>=repetition ): + occ -= stack.pop()==letter + if ch!=letter and len(stack)< k-max(0,(repetition-occ)): + stack.append(ch) + elif ch==letter and len(stack)+(total-counts)= 2} + return set(result) == expected + +seed: 2032 + +tests: + - name: "example_one" + in: + nums1: [1, 1, 3, 2] + nums2: [2, 3] + nums3: [3] + out: [3, 2] + - name: "example_two" + in: + nums1: [3, 1] + nums2: [2, 3] + nums3: [1, 2] + out: [2, 3, 1] + - name: "example_three_empty" + in: + nums1: [1, 2, 2] + nums2: [4, 3, 3] + nums3: [5] + out: [] + - name: "single_value_all_three" + in: + nums1: [1] + nums2: [1] + nums3: [1] + out: [1] + - name: "single_value_first_two" + in: + nums1: [7] + nums2: [7] + nums3: [8] + out: [7] + - name: "single_value_first_three" + in: + nums1: [9] + nums2: [8] + nums3: [9] + out: [9] + - name: "single_value_last_two" + in: + nums1: [6] + nums2: [5] + nums3: [5] + out: [5] + - name: "all_minimum" + in: + nums1: [1, 1, 1] + nums2: [1] + nums3: [1, 1] + out: [1] + - name: "all_maximum" + in: + nums1: [100] + nums2: [100, 100] + nums3: [100, 100, 100] + out: [100] + - name: "no_overlap_distinct" + in: + nums1: [1, 2, 3] + nums2: [4, 5, 6] + nums3: [7, 8, 9] + out: [] + - name: "pairwise_disjoint_results" + in: + nums1: [1, 2] + nums2: [2, 3] + nums3: [1, 3] + out: [1, 2, 3] + - name: "only_all_three" + in: + nums1: [4, 4, 8] + nums2: [4, 9] + nums3: [4, 10] + out: [4] + - name: "duplicates_only_one_array" + in: + nums1: [2, 2, 2, 5] + nums2: [3, 3] + nums3: [4, 4, 4] + out: [] + - name: "overlap_with_heavy_duplicates" + in: + nums1: [1, 1, 1, 2, 2] + nums2: [2, 2, 3, 3, 3] + nums3: [1, 3, 3, 4] + out: [1, 2, 3] + - name: "boundary_values_mixed" + in: + nums1: [1, 50, 100] + nums2: [1, 50, 99] + nums3: [2, 50, 100] + out: [1, 50, 100] + - name: "middle_value_pairs" + in: + nums1: [10, 20, 30, 40] + nums2: [20, 40, 50] + nums3: [10, 30, 50] + out: [10, 20, 30, 40, 50] + - name: "one_array_subsumed" + in: + nums1: [1, 2, 3, 4] + nums2: [2, 3] + nums3: [3, 4] + out: [2, 3, 4] + - name: "same_arrays" + in: + nums1: [5, 6, 7, 7] + nums2: [5, 6, 7] + nums3: [5, 6, 7, 7, 7] + out: [5, 6, 7] + - name: "alternating_pairs" + in: + nums1: [1, 3, 5, 7] + nums2: [2, 3, 6, 7] + nums3: [1, 2, 5, 6] + out: [1, 2, 3, 5, 6, 7] + - name: "long_first_array" + in: + nums1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + nums2: [2, 4, 6, 8, 10] + nums3: [1, 3, 5, 7, 9] + out: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + - name: "disjoint_then_common" + in: + nums1: [11, 12, 13, 14] + nums2: [21, 22, 23, 24] + nums3: [11, 21, 31, 41] + out: [11, 21] + - name: "three_way_and_pairwise" + in: + nums1: [1, 2, 3, 4, 5] + nums2: [2, 3, 6, 7] + nums3: [3, 4, 7, 8] + out: [2, 3, 4, 7] + - name: "near_upper_values" + in: + nums1: [96, 97, 98, 99, 100] + nums2: [95, 97, 99] + nums3: [94, 96, 98, 100] + out: [96, 97, 98, 99, 100] + - name: "repeated_pair_only" + in: + nums1: [12, 12, 13] + nums2: [14, 15, 15] + nums3: [12, 15, 16] + out: [12, 15] + - name: "small_universe" + in: + nums1: [1, 2, 1, 2] + nums2: [2, 3, 2] + nums3: [3, 1, 3] + out: [1, 2, 3] + - name: "singletons_all_different" + in: + nums1: [1] + nums2: [2] + nums3: [3] + out: [] + - name: "two_arrays_with_internal_noise" + in: + nums1: [1, 1, 2, 3, 3] + nums2: [3, 4, 4, 5] + nums3: [6, 7, 7, 8] + out: [3] + - name: "every_value_in_exactly_two" + in: + nums1: [10, 20, 30, 40] + nums2: [10, 20, 50, 60] + nums3: [30, 40, 50, 60] + out: [10, 20, 30, 40, 50, 60] + - name: "one_common_value_amid_range" + in: + nums1: [1, 2, 3, 4, 5, 6] + nums2: [7, 8, 9, 10, 11, 12] + nums3: [6, 13, 14, 15, 16, 17] + out: [6] + - name: "generated_small" + seed: 11 + in: + nums1: + gen: "array" + len: + gen: "int" + min: 1 + max: 12 + of: + gen: "int" + min: 1 + max: 12 + nums2: + gen: "array" + len: + gen: "int" + min: 1 + max: 12 + of: + gen: "int" + min: 1 + max: 12 + nums3: + gen: "array" + len: + gen: "int" + min: 1 + max: 12 + of: + gen: "int" + min: 1 + max: 12 + - name: "generated_medium" + seed: 22 + in: + nums1: + gen: "array" + len: + gen: "int" + min: 20 + max: 40 + of: + gen: "int" + min: 1 + max: 100 + nums2: + gen: "array" + len: + gen: "int" + min: 20 + max: 40 + of: + gen: "int" + min: 1 + max: 100 + nums3: + gen: "array" + len: + gen: "int" + min: 20 + max: 40 + of: + gen: "int" + min: 1 + max: 100 + - name: "generated_dense" + seed: 33 + in: + nums1: + gen: "array" + len: 60 + of: + gen: "int" + min: 1 + max: 8 + nums2: + gen: "array" + len: 60 + of: + gen: "int" + min: 1 + max: 8 + nums3: + gen: "array" + len: 60 + of: + gen: "int" + min: 1 + max: 8 + - name: "generated_sparse" + seed: 44 + in: + nums1: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + nums2: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + nums3: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + - name: "generated_balanced" + seed: 55 + in: + nums1: + gen: "array" + len: 35 + of: + gen: "int" + min: 1 + max: 100 + nums2: + gen: "array" + len: 70 + of: + gen: "int" + min: 1 + max: 100 + nums3: + gen: "array" + len: 5 + of: + gen: "int" + min: 1 + max: 100 + - name: "stress_max_all_values" + seed: 66 + in: + nums1: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + nums2: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + nums3: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + - name: "stress_max_dense" + seed: 77 + in: + nums1: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 3 + nums2: + gen: "array" + len: 100 + of: + gen: "int" + min: 98 + max: 100 + nums3: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 diff --git a/tests/2001-2500/2032. two-out-of-three/sol.py b/tests/2001-2500/2032. two-out-of-three/sol.py new file mode 100644 index 00000000..49b9af33 --- /dev/null +++ b/tests/2001-2500/2032. two-out-of-three/sol.py @@ -0,0 +1,9 @@ +class Solution(object): + def twoOutOfThree(self, nums1, nums2, nums3): + l=set(nums1+nums2+ nums3) + l1=[] + for i in l: + if i in nums1 and i in nums2 or i in nums1 and i in nums3 or i in nums2 and i in nums3 : + if i not in l1: + l1.append(i) + return l1 \ No newline at end of file diff --git a/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/manifest.yaml b/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/manifest.yaml new file mode 100644 index 00000000..cf531895 --- /dev/null +++ b/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/manifest.yaml @@ -0,0 +1,378 @@ +entry: + id: 2033 + title: "minimum-operations-to-make-a-uni-value-grid" + params: + grid: + type: array + items: + type: array + items: + type: int + x: + type: int + call: + cpp: "Solution().minOperations({grid}, {x})" + rust: "Solution::min_operations({grid}, {x})" + python3: "Solution().minOperations({grid}, {x})" + python2: "Solution().minOperations({grid}, {x})" + ruby: "min_operations({grid}, {x})" + java: "new Solution().minOperations({grid}, {x})" + csharp: "new Solution().MinOperations({grid}, {x})" + kotlin: "Solution().minOperations({grid}, {x})" + go: "minOperations({grid}, {x})" + dart: "Solution().minOperations({grid}, {x})" + swift: "Solution().minOperations({grid}, {x})" + typescript: "minOperations({grid}, {x})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minOperations(grid, x, {result})" + checker: | + class Checker: + def minOperations(self, grid, x, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + values = [v for row in grid for v in row] + base = values[0] + if any((v - base) % x != 0 for v in values): + return result == -1 + values.sort() + median = values[len(values) // 2] + expected = sum(abs(v - median) // x for v in values) + return result == expected + +seed: 2033 + +tests: + - name: "example_1" + in: + grid: + elemType: "int" + value: + - [2, 4] + - [6, 8] + x: 2 + out: 4 + - name: "example_2" + in: + grid: + elemType: "int" + value: + - [1, 5] + - [2, 3] + x: 1 + out: 5 + - name: "example_3_impossible" + in: + grid: + elemType: "int" + value: + - [1, 2] + - [3, 4] + x: 2 + out: -1 + - name: "single_cell" + in: + grid: + elemType: "int" + value: + - [10000] + x: 9999 + out: 0 + - name: "two_cells_unit_step" + in: + grid: + elemType: "int" + value: + - [1, 3] + x: 1 + out: 2 + - name: "two_cells_large_step" + in: + grid: + elemType: "int" + value: + - [1, 5] + x: 2 + out: 2 + - name: "same_values" + in: + grid: + elemType: "int" + value: + - [7, 7] + - [7, 7] + x: 7 + out: 0 + - name: "incompatible_residue" + in: + grid: + elemType: "int" + value: + - [2, 4] + - [6, 7] + x: 2 + out: -1 + - name: "odd_count_median" + in: + grid: + elemType: "int" + value: + - [1, 7, 13] + x: 3 + out: 4 + - name: "even_count_lower_median" + in: + grid: + elemType: "int" + value: + - [1, 4] + - [7, 10] + x: 3 + out: 4 + - name: "column_grid" + in: + grid: + elemType: "int" + value: + - [10] + - [13] + - [16] + - [19] + x: 3 + out: 4 + - name: "negative_direction_moves" + in: + grid: + elemType: "int" + value: + - [10, 4] + - [7, 13] + x: 3 + out: 4 + - name: "large_x_one_move" + in: + grid: + elemType: "int" + value: + - [1, 10000] + x: 9999 + out: 1 + - name: "large_x_impossible" + in: + grid: + elemType: "int" + value: + - [1, 9999] + x: 9999 + out: -1 + - name: "four_by_one" + in: + grid: + elemType: "int" + value: + - [2] + - [8] + - [14] + - [20] + x: 6 + out: 4 + - name: "duplicates_below_median" + in: + grid: + elemType: "int" + value: + - [1, 1, 1, 7] + x: 3 + out: 2 + - name: "duplicates_above_median" + in: + grid: + elemType: "int" + value: + - [1, 7, 7, 7] + x: 3 + out: 2 + - name: "three_by_three_center" + in: + grid: + elemType: "int" + value: + - [4, 10, 16] + - [22, 28, 34] + - [40, 46, 52] + x: 6 + out: 20 + - name: "mixed_rectangular" + in: + grid: + elemType: "int" + value: + - [5, 11, 17, 23] + - [29, 35, 41, 47] + x: 6 + out: 16 + - name: "all_minimum_values" + in: + grid: + elemType: "int" + value: + - [1, 1, 1] + - [1, 1, 1] + x: 1 + out: 0 + - name: "all_maximum_values" + in: + grid: + elemType: "int" + value: + - [10000, 10000] + - [10000, 10000] + x: 1 + out: 0 + - name: "non_unit_x_residue" + in: + grid: + elemType: "int" + value: + - [3, 9] + - [15, 21] + x: 6 + out: 4 + - name: "non_unit_x_bad_residue" + in: + grid: + elemType: "int" + value: + - [3, 9] + - [15, 20] + x: 6 + out: -1 + - name: "balanced_values" + in: + grid: + elemType: "int" + value: + - [2, 8, 14] + - [14, 8, 2] + x: 6 + out: 4 + - name: "wide_range_unit" + in: + grid: + elemType: "int" + value: + - [1, 2, 3, 4, 5] + x: 1 + out: 6 + - name: "wide_range_step_two" + in: + grid: + elemType: "int" + value: + - [2, 4, 6, 8, 10] + x: 2 + out: 6 + - name: "two_by_three" + in: + grid: + elemType: "int" + value: + - [4, 4, 10] + - [16, 22, 22] + x: 6 + out: 7 + - name: "one_row_unsorted" + in: + grid: + elemType: "int" + value: + - [19, 1, 13, 7] + x: 6 + out: 4 + - name: "one_column_unsorted" + in: + grid: + elemType: "int" + value: + - [19] + - [1] + - [13] + - [7] + x: 6 + out: 4 + - name: "near_upper_bound" + in: + grid: + elemType: "int" + value: + - [9990, 9994] + - [9998, 10000] + x: 2 + out: 7 + - name: "upper_bound_incompatible" + in: + grid: + elemType: "int" + value: + - [9998, 10000] + x: 3 + out: -1 + - name: "single_row_three_values" + in: + grid: + elemType: "int" + value: + - [100, 400, 700] + x: 100 + out: 6 + - name: "generated_small" + seed: 203301 + in: + grid: + gen: "array" + len: 1 + elemType: "int" + of: + gen: "array" + len: 25 + elemType: "int" + of: + gen: "int" + min: 1 + max: 10000 + x: + gen: "int" + min: 1 + max: 10000 + - name: "explicit_rectangular_stress" + in: + grid: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + - [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + - [21, 22, 23, 24, 25, 26, 27, 28, 29, 30] + - [31, 32, 33, 34, 35, 36, 37, 38, 39, 40] + - [41, 42, 43, 44, 45, 46, 47, 48, 49, 50] + x: 1 + out: 625 + - name: "explicit_boundary_stress" + in: + grid: + elemType: "int" + value: + - [9951, 9952, 9953, 9954, 9955, 9956, 9957, 9958, 9959, 9960] + - [9961, 9962, 9963, 9964, 9965, 9966, 9967, 9968, 9969, 9970] + - [9971, 9972, 9973, 9974, 9975, 9976, 9977, 9978, 9979, 9980] + - [9981, 9982, 9983, 9984, 9985, 9986, 9987, 9988, 9989, 9990] + - [9991, 9992, 9993, 9994, 9995, 9996, 9997, 9998, 9999, 10000] + x: 1 + out: 625 diff --git a/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/sol.py b/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/sol.py new file mode 100644 index 00000000..b62c58d6 --- /dev/null +++ b/tests/2001-2500/2033. minimum-operations-to-make-a-uni-value-grid/sol.py @@ -0,0 +1,27 @@ +class Solution: + def minOperations(self, grid: List[List[int]], x: int) -> int: + arr = [] + + # flatten grid + for row in grid: + for v in row: + arr.append(v) + + # check divisibility + base = arr[0] + for v in arr: + if abs(v - base) % x != 0: + return -1 + + # sort + arr.sort() + + # median + median = arr[len(arr)//2] + + # count operations + ops = 0 + for v in arr: + ops += abs(v - median) // x + + return ops \ No newline at end of file diff --git a/tests/2001-2500/2034. stock-price-fluctuation/sol.py b/tests/2001-2500/2034. stock-price-fluctuation/sol.py new file mode 100644 index 00000000..789c42b8 --- /dev/null +++ b/tests/2001-2500/2034. stock-price-fluctuation/sol.py @@ -0,0 +1,42 @@ +class Solution: + from sortedcontainers import SortedDict + class StockPrice: + + def __init__(self): + #For each price map to a list of timestamps + #We need to map to a list because the same price can exist at different timestamps + self.price_to_t=SortedDict() + #For each timestamp map to a price + self.t_to_price=SortedDict() + + def update(self, timestamp: int, price: int) -> None: + if timestamp in self.t_to_price: + oldprice = self.t_to_price[timestamp] + self.price_to_t[oldprice].pop(self.price_to_t[oldprice].index(timestamp)) + if not len(self.price_to_t[oldprice]): + self.price_to_t.pop(oldprice) + self.t_to_price[timestamp]=price + if price not in self.price_to_t: + self.price_to_t[price]=[timestamp] + else: + self.price_to_t[price].append(timestamp) + + def current(self) -> int: + t,p =self.t_to_price.peekitem(-1) + return p + + def maximum(self) -> int: + p,t= self.price_to_t.peekitem(-1) + return p + + def minimum(self) -> int: + p,t= self.price_to_t.peekitem(0) + return p + + + # Your StockPrice object will be instantiated and called as such: + # obj = StockPrice() + # obj.update(timestamp,price) + # param_2 = obj.current() + # param_3 = obj.maximum() + # param_4 = obj.minimum() diff --git a/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/manifest.yaml b/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/manifest.yaml new file mode 100644 index 00000000..87b0a2de --- /dev/null +++ b/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/manifest.yaml @@ -0,0 +1,257 @@ +entry: + id: 2035 + title: "partition-array-into-two-arrays-to-minimize-sum-difference" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().minimumDifference({nums})" + rust: "Solution::minimum_difference({nums})" + python3: "Solution().minimumDifference({nums})" + python2: "Solution().minimumDifference({nums})" + ruby: "minimum_difference({nums})" + java: "new Solution().minimumDifference({nums})" + csharp: "new Solution().MinimumDifference({nums})" + kotlin: "Solution().minimumDifference({nums})" + go: "minimumDifference({nums})" + dart: "Solution().minimumDifference({nums})" + swift: "Solution().minimumDifference({nums})" + typescript: "minimumDifference({nums})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().minimumDifference(nums, {result})" + checker: | + class Checker: + def minimumDifference(self, nums, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + m = len(nums) + if m < 2 or m % 2 != 0 or m > 30: + return False + n = m // 2 + total = sum(nums) + left = [[] for _ in range(n + 1)] + right = [[] for _ in range(n + 1)] + for mask in range(1 << n): + k = mask.bit_count() + a = 0 + b = 0 + for i in range(n): + if mask & (1 << i): + a += nums[i] + b += nums[n + i] + left[k].append(a) + right[k].append(b) + for values in left: + values.sort() + import bisect + best = None + for k in range(n + 1): + candidates = left[k] + for s in right[n - k]: + target = (total // 2) - s + pos = bisect.bisect_left(candidates, target) + for j in (pos - 1, pos): + if 0 <= j < len(candidates): + diff = abs(total - 2 * (candidates[j] + s)) + best = diff if best is None else min(best, diff) + return result == best + +seed: 20352035 + +tests: + - name: "example_one" + in: + nums: [3, 9, 7, 3] + out: 2 + - name: "example_two" + in: + nums: [-36, 36] + out: 72 + - name: "example_three" + in: + nums: [2, -1, 0, 4, -2, -9] + out: 0 + - name: "two_equal_zero" + in: + nums: [0, 0] + out: 0 + - name: "two_same_positive" + in: + nums: [7, 7] + out: 0 + - name: "two_opposite" + in: + nums: [-10000000, 10000000] + out: 20000000 + - name: "four_all_equal" + in: + nums: [5, 5, 5, 5] + out: 0 + - name: "four_mixed_sign" + in: + nums: [-5, -4, 10, 1] + out: 8 + - name: "four_extremes" + in: + nums: [-10000000, -10000000, 10000000, 10000000] + out: 0 + - name: "six_balanced" + in: + nums: [1, 2, 3, 4, 5, 6] + out: 1 + - name: "six_duplicates" + in: + nums: [8, 8, 8, 8, 8, 8] + out: 0 + - name: "six_large_odd_total" + in: + nums: [10000000, 10000000, 10000000, 10000000, 10000000, 9999999] + out: 1 + - name: "eight_powers" + in: + nums: [1, 2, 4, 8, 16, 32, 64, 128] + out: 15 + - name: "eight_negative" + in: + nums: [-1, -2, -3, -4, -5, -6, -7, -8] + out: 0 + - name: "eight_zero_and_large" + in: + nums: [0, 0, 0, 0, 10000000, 10000000, -10000000, -10000000] + out: 0 + - name: "ten_alternating" + in: + nums: [100, -100, 99, -99, 98, -98, 97, -97, 96, -96] + out: 184 + - name: "ten_uneven" + in: + nums: [1, 1, 1, 1, 1, 1, 1, 1, 1, 2] + out: 1 + - name: "twelve_sequential" + in: + nums: [-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6] + - name: "fourteen_sparse" + in: + nums: [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1] + - name: "sixteen_repeated_blocks" + in: + nums: [3, 3, 3, 3, 3, 3, 3, 3, -2, -2, -2, -2, -2, -2, -2, -2] + - name: "eighteen_signed_steps" + in: + nums: [-9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9] + - name: "twenty_randomish" + in: + nums: [17, -23, 41, 5, -8, 19, -31, 7, 13, -2, 29, -11, 3, 37, -19, 2, -7, 43, -5, 11] + - name: "twenty_two_extreme_mix" + in: + nums: [10000000, -10000000, 9999999, -9999999, 8888888, -8888888, 7777777, -7777777, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7] + - name: "twenty_four_duplicates" + in: + nums: [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11] + - name: "twenty_six_progression" + in: + nums: [-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + - name: "twenty_eight_high_values" + in: + nums: [9999991, 9999983, 9999973, 9999967, 9999959, 9999943, 9999931, 9999929, -9999919, -9999907, -9999901, -9999899, -9999887, -9999871, -9999857, -9999851, 1234567, -1234567, 7654321, -7654321, 3141592, -3141592, 2718281, -2718281, 42, -42, 100, -100] + - name: "thirty_maximum_balanced" + in: + nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15] + - name: "generated_small_values" + seed: 101 + in: + nums: + gen: "array" + len: 10 + of: + gen: "int" + min: -20 + max: 20 + distinct: false + sorted: false + - name: "generated_medium_values" + seed: 202 + in: + nums: + gen: "array" + len: 16 + of: + gen: "int" + min: -1000 + max: 1000 + distinct: false + sorted: false + - name: "generated_large_values" + seed: 303 + in: + nums: + gen: "array" + len: 24 + of: + gen: "int" + min: -10000000 + max: 10000000 + distinct: false + sorted: false + - name: "generated_maximum_values" + seed: 404 + in: + nums: + gen: "array" + len: 30 + of: + gen: "int" + min: -10000000 + max: 10000000 + distinct: false + sorted: false + - name: "generated_maximum_narrow_range" + seed: 505 + in: + nums: + gen: "array" + len: 30 + of: + gen: "int" + min: -3 + max: 3 + distinct: false + sorted: false + - name: "thirty_maximum_same_sign" + in: + nums: [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990, 9999989, 9999988, 9999987, 9999986, -10000000, -9999999, -9999998, -9999997, -9999996, -9999995, -9999994, -9999993, -9999992, -9999991, -9999990, -9999989, -9999988, -9999987, -9999986] + - name: "generated_odd_total_candidates" + seed: 606 + in: + nums: + gen: "array" + len: 14 + of: + gen: "int" + min: -999 + max: 1000 + distinct: false + sorted: false + - name: "generated_maximum_duplicates" + seed: 707 + in: + nums: + gen: "array" + len: 30 + of: + gen: "int" + min: -1 + max: 1 + distinct: false + sorted: false diff --git a/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/sol.py b/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/sol.py new file mode 100644 index 00000000..7ed42556 --- /dev/null +++ b/tests/2001-2500/2035. partition-array-into-two-arrays-to-minimize-sum-difference/sol.py @@ -0,0 +1,88 @@ +# https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/ +class Solution: + def minimumDifference(self, arr) -> int: + """ +We need to divide the 2n elements into two groups containing exactly n +elements each such that the absolute difference between their sums is +as small as possible + +Let the sum of one chosen group be S and the total sum of the array be T + +The other group's sum is T - S + +The required difference is + +|S - (T - S)| = |2S - T| + +Therefore, instead of directly thinking about two partitions, the problem +becomes choosing exactly n elements whose sum is as close as possible to +T / 2 + +Trying all combinations of n elements takes O(C(2n, n)), which is too +expensive + +Since the array length is at most 30, split it into two halves of size n + +For each half, generate all subset sums and group them by the number of +elements chosen + +mp[k] stores all possible sums obtained by selecting exactly k elements +from that half + +Suppose we choose k elements from the right half + +Then we must choose n - k elements from the left half so that the total +number of selected elements is exactly n + +For every sum from the right half, find a compatible sum from the left +half such that their combined sum is as close as possible to T / 2 + +The left sums are sorted, so binary search can be used to find the +closest candidates efficiently + +For each right sum, only the two neighbors around the insertion position +need to be checked because one of them gives the minimum difference + +Update the answer using + +|T - 2 * (left_sum + right_sum)| + +This meet-in-the-middle approach reduces the complexity from exponential +in 2n to roughly O(n * 2^n), which is efficient for n ≤ 15 +""" + n=len(arr) + + def gen(arr): + max_len=len(arr) + mp=defaultdict(list) + for mask in range(1<>1 + mp_left=gen(arr[:mid]) + mp_right=gen(arr[mid:]) + for k in mp_left: + mp_left[k].sort() + for k in mp_right: + mp_right[k].sort() + # print(mp_left) + # print(mp_right) + ans=float('inf') + total=sum(arr) + for val in mp_right: + #we have one of size val + #other one size is n-val + left_sz=len(arr)//2-val + #to minimise a-b = 0 -> a+b=s + #2a=x+s -> a=(x+s)/2 + #2s-2b=x+s + #x=s-2b + for value in mp_right[val]: + idx=bisect.bisect_left(mp_left[left_sz],total//2-value) + ans=min(ans,abs(total-2*((mp_left[left_sz][idx-1] +value) if idx>0 else float('inf'))),abs(total-2*((mp_left[left_sz][idx]+value if idx int: + seats.sort() + students.sort() + ans=0 + for i in range(len(seats)): + ans+=abs(seats[i]-students[i]) + return ans \ No newline at end of file diff --git a/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/manifest.yaml b/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/manifest.yaml new file mode 100644 index 00000000..879c2593 --- /dev/null +++ b/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/manifest.yaml @@ -0,0 +1,207 @@ +entry: + id: 2038 + title: "remove-colored-pieces-if-both-neighbors-are-the-same-color" + params: + colors: + type: string + call: + cpp: "Solution().winnerOfGame({colors})" + rust: "Solution::winner_of_game({colors})" + python3: "Solution().winnerOfGame({colors})" + python2: "Solution().winnerOfGame({colors})" + ruby: "winner_of_game({colors})" + java: "new Solution().winnerOfGame({colors})" + csharp: "new Solution().WinnerOfGame({colors})" + kotlin: "Solution().winnerOfGame({colors})" + go: "winnerOfGame({colors})" + dart: "Solution().winnerOfGame({colors})" + swift: "Solution().winnerOfGame({colors})" + typescript: "winnerOfGame({colors})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().winnerOfGame(colors, {result})" + checker: | + class Checker: + def winnerOfGame(self, colors, result): + if not isinstance(result, bool): + return False + a = 0 + b = 0 + i = 0 + while i < len(colors): + j = i + while j < len(colors) and colors[j] == colors[i]: + j += 1 + if j - i >= 3: + if colors[i] == 'A': + a += j - i - 2 + else: + b += j - i - 2 + i = j + return result == (a > b) + +seed: 2038 + +tests: + - name: "example_1" + in: + colors: "AAABABB" + out: true + - name: "example_2" + in: + colors: "AA" + out: false + - name: "example_3" + in: + colors: "ABBBBBBBAAA" + out: false + - name: "single_a" + in: + colors: "A" + out: false + - name: "single_b" + in: + colors: "B" + out: false + - name: "two_different" + in: + colors: "AB" + out: false + - name: "three_a" + in: + colors: "AAA" + out: true + - name: "three_b" + in: + colors: "BBB" + out: false + - name: "four_a" + in: + colors: "AAAA" + out: true + - name: "four_b" + in: + colors: "BBBB" + out: false + - name: "alternating_short" + in: + colors: "ABABAB" + out: false + - name: "alternating_long" + in: + colors: "ABABABABABABABABABAB" + out: false + - name: "equal_three_runs" + in: + colors: "AAABBB" + out: false + - name: "a_one_more" + in: + colors: "AAABBBB" + out: false + - name: "b_one_more" + in: + colors: "AAAABBB" + out: true + - name: "both_long_a_wins" + in: + colors: "AAAAABBBB" + out: true + - name: "both_long_b_wins" + in: + colors: "AAABBBBB" + out: false + - name: "same_runs_with_separators" + in: + colors: "AAABAAAB" + out: true + - name: "internal_a_run" + in: + colors: "BAAAB" + out: true + - name: "internal_b_run" + in: + colors: "ABBBA" + out: false + - name: "edge_run_a" + in: + colors: "AAAAB" + out: true + - name: "edge_run_b" + in: + colors: "BAAAA" + out: true + - name: "no_moves_with_pairs" + in: + colors: "AABBBAA" + out: false + - name: "many_small_runs" + in: + colors: "AABBAABBAABB" + out: false + - name: "a_runs_sum_three" + in: + colors: "AAAABAAAB" + out: true + - name: "b_runs_sum_three" + in: + colors: "ABBBBABBB" + out: false + - name: "balanced_disjoint_runs" + in: + colors: "AAABBBAAABBB" + out: false + - name: "long_a_against_many_b" + in: + colors: "AAAAAAAAAABBBBBB" + out: true + - name: "many_a_against_long_b" + in: + colors: "AAAAAABBBBBBBBBB" + out: false + - name: "all_a_max_small" + in: + colors: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + out: true + - name: "all_b_max_small" + in: + colors: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + out: false + - name: "isolated_a_between_b" + in: + colors: "BBABB" + out: false + - name: "isolated_b_between_a" + in: + colors: "AABAA" + out: false + - name: "alternating_runs_a_edge" + in: + colors: "AAABBAABBBAAAAA" + out: true + - name: "alternating_runs_b_edge" + in: + colors: "BBBAABBBAAABBBBB" + out: false + - name: "generated_small" + seed: 12038 + in: + colors: + gen: "str" + len: 137 + alphabet: "AB" + - name: "generated_maximum" + seed: 22038 + in: + colors: + gen: "str" + len: 100000 + alphabet: "AB" diff --git a/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/sol.py b/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/sol.py new file mode 100644 index 00000000..029d8f41 --- /dev/null +++ b/tests/2001-2500/2038. remove-colored-pieces-if-both-neighbors-are-the-same-color/sol.py @@ -0,0 +1,16 @@ +class Solution: + def winnerOfGame(self, colors: str) -> bool: + a, b = 0, 0 + idx = 0 + n = len(colors) + while idx < n: + j = idx + ch = colors[idx] + while j < n and colors[j] == ch: + j += 1 + if ch == 'A' and j - idx >= 3: + a += j - idx - 2 + elif ch == 'B' and j - idx >= 3: + b += j - idx - 2 + idx = j + return a > b \ No newline at end of file diff --git a/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/manifest.yaml b/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/manifest.yaml new file mode 100644 index 00000000..a23b5757 --- /dev/null +++ b/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/manifest.yaml @@ -0,0 +1,440 @@ +entry: + id: 2039 + title: "the-time-when-the-network-becomes-idle" + params: + edges: + type: array + items: + type: array + items: + type: int + patience: + type: array + items: + type: int + call: + cpp: "Solution().networkBecomesIdle({edges}, {patience})" + rust: "Solution::network_becomes_idle({edges}, {patience})" + python3: "Solution().networkBecomesIdle({edges}, {patience})" + python2: "Solution().networkBecomesIdle({edges}, {patience})" + ruby: "network_becomes_idle({edges}, {patience})" + java: "new Solution().networkBecomesIdle({edges}, {patience})" + csharp: "new Solution().NetworkBecomesIdle({edges}, {patience})" + kotlin: "Solution().networkBecomesIdle({edges}, {patience})" + go: "networkBecomesIdle({edges}, {patience})" + dart: "Solution().networkBecomesIdle({edges}, {patience})" + swift: "Solution().networkBecomesIdle({edges}, {patience})" + typescript: "networkBecomesIdle({edges}, {patience})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().networkBecomesIdle(edges, patience, {result})" + checker: | + class Checker: + def networkBecomesIdle(self, edges, patience, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(patience) + graph = [[] for _ in range(n)] + for u, v in edges: + graph[u].append(v) + graph[v].append(u) + dist = [-1] * n + dist[0] = 0 + queue = [0] + for u in queue: + for v in graph[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + queue.append(v) + expected = 1 + for i in range(1, n): + rtt = 2 * dist[i] + last = rtt if patience[i] >= rtt else ((rtt - 1) // patience[i]) * patience[i] + rtt + expected = max(expected, last + 1) + return result == expected + +seed: 2039 + +tests: + - name: "example_path" + in: + edges: + - [0, 1] + - [1, 2] + patience: [0, 2, 1] + out: 8 + - name: "example_triangle" + in: + edges: + - [0, 1] + - [0, 2] + - [1, 2] + patience: [0, 10, 10] + out: 3 + - name: "two_servers_fast" + in: + edges: + - [0, 1] + patience: [0, 1] + out: 4 + - name: "two_servers_equal_rtt" + in: + edges: + - [0, 1] + patience: [0, 2] + out: 3 + - name: "two_servers_slow" + in: + edges: + - [0, 1] + patience: [0, 100000] + out: 3 + - name: "star_three" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + patience: [0, 1, 2, 3] + out: 4 + - name: "star_all_fast" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [0, 4] + - [0, 5] + patience: [0, 1, 1, 1, 1, 1] + out: 4 + - name: "path_four_fast" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + patience: [0, 1, 1, 1] + out: 12 + - name: "path_four_slow" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + patience: [0, 100, 100, 100] + out: 7 + - name: "path_five_mixed" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + patience: [0, 1, 3, 2, 1] + out: 16 + - name: "path_six_periods" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + patience: [0, 2, 4, 3, 5, 1] + out: 20 + - name: "cycle_four" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 0] + patience: [0, 1, 1, 1] + out: 8 + - name: "cycle_five" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 0] + patience: [0, 1, 2, 3, 1] + out: 8 + - name: "shortcut_path" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [0, 3] + - [3, 4] + patience: [0, 1, 1, 1, 1] + out: 8 + - name: "branching_graph" + in: + edges: + - [0, 1] + - [0, 2] + - [1, 3] + - [1, 4] + - [2, 5] + - [5, 6] + patience: [0, 1, 2, 2, 3, 1, 4] + out: 11 + - name: "dense_six" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [1, 2] + - [1, 4] + - [2, 4] + - [2, 5] + - [3, 5] + - [4, 5] + patience: [0, 1, 2, 10, 1, 3] + out: 8 + - name: "deep_branch" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [1, 5] + - [5, 6] + - [0, 7] + patience: [0, 1, 1, 2, 10, 1, 1, 2] + out: 12 + - name: "patience_boundary_depth_two" + in: + edges: + - [0, 1] + - [1, 2] + patience: [0, 3, 4] + out: 5 + - name: "patience_just_below" + in: + edges: + - [0, 1] + - [1, 2] + patience: [0, 3, 3] + out: 8 + - name: "large_patience_mix" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [0, 4] + - [4, 5] + - [5, 6] + - [6, 7] + patience: [0, 100000, 99999, 1, 100000, 1, 2, 100000] + out: 12 + - name: "long_path_ten" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + patience: [0, 1, 2, 3, 4, 5, 6, 7, 8, 1] + out: 36 + - name: "wide_two_level" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [0, 4] + - [1, 5] + - [1, 6] + - [2, 7] + - [3, 8] + patience: [0, 2, 3, 4, 5, 1, 2, 1, 10] + out: 8 + - name: "leaf_with_many_resends" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + patience: [0, 1, 1, 1, 1] + out: 16 + - name: "all_max_patience_small" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + patience: [0, 100000, 100000, 100000, 100000, 100000] + out: 11 + - name: "complete_four" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [1, 2] + - [1, 3] + - [2, 3] + patience: [0, 1, 2, 100000] + out: 4 + - name: "chain_with_chords" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [0, 3] + - [1, 4] + patience: [0, 1, 1, 1, 2, 1] + out: 12 + - name: "uneven_tree" + in: + edges: + - [0, 1] + - [1, 2] + - [1, 3] + - [3, 4] + - [3, 5] + - [5, 6] + - [5, 7] + - [7, 8] + patience: [0, 2, 1, 4, 1, 2, 3, 1, 2] + out: 19 + - name: "single_far_fast" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + patience: [0, 1, 1, 1, 1, 1, 1, 1] + out: 28 + - name: "single_far_slow" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + patience: [0, 100000, 100000, 100000, 100000, 100000, 100000, 100000] + out: 15 + - name: "dense_eight" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [1, 4] + - [2, 4] + - [2, 5] + - [3, 5] + - [3, 6] + - [4, 6] + - [4, 7] + - [5, 7] + patience: [0, 1, 1, 2, 1, 3, 2, 1] + out: 12 + - name: "large_explicit_path" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + - [9, 10] + - [10, 11] + - [11, 12] + - [12, 13] + - [13, 14] + - [14, 15] + - [15, 16] + - [16, 17] + - [17, 18] + - [18, 19] + patience: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1] + out: 76 + - name: "large_explicit_star" + in: + edges: + - [0, 1] + - [0, 2] + - [0, 3] + - [0, 4] + - [0, 5] + - [0, 6] + - [0, 7] + - [0, 8] + - [0, 9] + - [0, 10] + - [0, 11] + - [0, 12] + - [0, 13] + - [0, 14] + - [0, 15] + - [0, 16] + - [0, 17] + - [0, 18] + - [0, 19] + patience: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 100000] + out: 4 + - name: "triangle_fast_resend" + in: + edges: + - [0, 1] + - [0, 2] + - [1, 2] + patience: [0, 1, 1] + out: 4 + - name: "tree_depth_three_boundary" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + patience: [0, 2, 4, 5] + out: 12 + - name: "two_branches_long_leaf" + in: + edges: + - [0, 1] + - [1, 2] + - [2, 3] + - [0, 4] + - [4, 5] + patience: [0, 2, 2, 1, 10, 1] + out: 12 diff --git a/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/sol.py b/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/sol.py new file mode 100644 index 00000000..eb2ee7c1 --- /dev/null +++ b/tests/2001-2500/2039. the-time-when-the-network-becomes-idle/sol.py @@ -0,0 +1,36 @@ +class Solution(object): + def networkBecomesIdle(self, edges, patience): + """ + :type edges: List[List[int]] + :type patience: List[int] + :rtype: int + """ + n = len(patience) + + graph = defaultdict(list) + for u, v in edges: + graph[u].append(v) + graph[v].append(u) + + dist = [float('inf')] * n + dist[0] = 0 + queue = deque([0]) + + while queue: + u = queue.popleft() + for v in graph[u]: + if dist[v] == float('inf'): + dist[v] = dist[u] + 1 + queue.append(v) + + max_time = 0 + for i in range(1, n): + rtt = 2 * dist[i] + if patience[i] >= rtt: + last_reply = rtt + else: + last_send = ((rtt - 1) // patience[i]) * patience[i] + last_reply = last_send + rtt + max_time = max(max_time, last_reply) + + return max_time + 1 \ No newline at end of file diff --git a/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/manifest.yaml b/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/manifest.yaml new file mode 100644 index 00000000..724898fd --- /dev/null +++ b/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/manifest.yaml @@ -0,0 +1,319 @@ +entry: + id: 2040 + title: "kth-smallest-product-of-two-sorted-arrays" + params: + nums1: + type: array + items: + type: int + nums2: + type: array + items: + type: int + k: + type: long + call: + cpp: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + rust: "Solution::kth_smallest_product({nums1}, {nums2}, {k})" + python3: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + python2: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + ruby: "kth_smallest_product({nums1}, {nums2}, {k})" + java: "new Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + csharp: "new Solution().KthSmallestProduct({nums1}, {nums2}, {k})" + kotlin: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + go: "kthSmallestProduct({nums1}, {nums2}, {k})" + dart: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + swift: "Solution().kthSmallestProduct({nums1}, {nums2}, {k})" + typescript: "kthSmallestProduct({nums1}, {nums2}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 3000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().check(nums1, nums2, k, {result})" + checker: | + class Checker: + def check(self, nums1, nums2, k, result): + import bisect + def count(x): + total = 0 + for a in nums1: + if a > 0: + total += bisect.bisect_right(nums2, x // a) + elif a < 0: + q, r = divmod(x, a) + if r != 0: + q += 1 + total += len(nums2) - bisect.bisect_left(nums2, q) + elif x >= 0: + total += len(nums2) + return total + lo, hi = -10000000000, 10000000000 + while lo < hi: + mid = (lo + hi) // 2 + if count(mid) < k: + lo = mid + 1 + else: + hi = mid + return result == lo + +seed: 2040 + +tests: + - name: "example_positive_second" + in: + nums1: [2, 5] + nums2: [3, 4] + k: 2 + out: 8 + - name: "example_zero_boundary" + in: + nums1: [-4, -2, 0, 3] + nums2: [2, 4] + k: 6 + out: 0 + - name: "example_mixed_negative" + in: + nums1: [-2, -1, 0, 1, 2] + nums2: [-3, -1, 2, 4, 5] + k: 3 + out: -6 + - name: "single_positive" + in: + nums1: [7] + nums2: [6] + k: 1 + out: 42 + - name: "single_negative" + in: + nums1: [-7] + nums2: [6] + k: 1 + out: -42 + - name: "single_zero" + in: + nums1: [0] + nums2: [-100000, 100000] + k: 2 + out: 0 + - name: "all_negative_arrays_first" + in: + nums1: [-5, -3, -1] + nums2: [2, 4] + k: 1 + out: -20 + - name: "all_negative_arrays_last" + in: + nums1: [-5, -3, -1] + nums2: [2, 4] + k: 6 + out: -2 + - name: "negative_times_negative" + in: + nums1: [-4, -2] + nums2: [-5, -1] + k: 2 + out: 4 + - name: "positive_times_negative" + in: + nums1: [1, 3, 8] + nums2: [-7, -2] + k: 4 + out: -7 + - name: "zeros_duplicate_products" + in: + nums1: [-1, 0, 0, 0, 2] + nums2: [-3, 0, 0, 4] + k: 7 + out: 0 + - name: "zero_first_product" + in: + nums1: [-2, 0, 4] + nums2: [-3, -1, 2] + k: 1 + out: -12 + - name: "zero_last_product" + in: + nums1: [-2, 0, 4] + nums2: [-3, -1, 2] + k: 9 + out: 8 + - name: "duplicate_negatives" + in: + nums1: [-2, -2, 1] + nums2: [2, 2, 3] + k: 3 + out: -4 + - name: "duplicate_positives" + in: + nums1: [1, 1, 4] + nums2: [2, 2, 5] + k: 5 + out: 5 + - name: "all_ones" + in: + nums1: [1, 1, 1, 1] + nums2: [1, 1, 1] + k: 6 + out: 1 + - name: "min_product_extreme" + in: + nums1: [-100000] + nums2: [100000] + k: 1 + out: -10000000000 + - name: "max_product_extreme" + in: + nums1: [100000] + nums2: [100000] + k: 1 + out: 10000000000 + - name: "extreme_mixed_low" + in: + nums1: [-100000, -1, 0, 1, 100000] + nums2: [-100000, -2, 0, 2, 100000] + k: 1 + out: -10000000000 + - name: "extreme_mixed_high" + in: + nums1: [-100000, -1, 0, 1, 100000] + nums2: [-100000, -2, 0, 2, 100000] + k: 25 + out: 10000000000 + - name: "near_zero_negative" + in: + nums1: [-3, -1, 2] + nums2: [-4, 1, 5] + k: 4 + out: -3 + - name: "near_zero_positive" + in: + nums1: [-3, -1, 2] + nums2: [-4, 1, 5] + k: 6 + out: 2 + - name: "unequal_lengths" + in: + nums1: [-5, 0, 2, 9] + nums2: [-3, 4] + k: 5 + out: 0 + - name: "two_by_two_middle" + in: + nums1: [-2, 3] + nums2: [-4, 5] + k: 2 + out: -10 + - name: "all_zero" + in: + nums1: [0, 0, 0] + nums2: [0, 0] + k: 4 + out: 0 + - name: "negative_division_case" + in: + nums1: [-5, -2] + nums2: [-4, 3] + k: 3 + out: 8 + - name: "positive_division_case" + in: + nums1: [2, 5] + nums2: [-3, 7] + k: 3 + out: 14 + - name: "many_signs" + in: + nums1: [-6, -3, -1, 0, 2, 5] + nums2: [-7, -2, 0, 4, 8] + k: 10 + out: -4 + - name: "many_signs_upper" + in: + nums1: [-6, -3, -1, 0, 2, 5] + nums2: [-7, -2, 0, 4, 8] + k: 29 + out: 40 + - name: "all_positive_order" + in: + nums1: [2, 3, 10] + nums2: [1, 4, 9] + k: 7 + out: 27 + - name: "all_negative_order" + in: + nums1: [-10, -3, -2] + nums2: [-9, -4, -1] + k: 7 + out: 27 + - name: "large_magnitude_small_length" + in: + nums1: [-99999, -50000, 50000, 99999] + nums2: [-99998, -2, 2, 99998] + k: 8 + out: -100000 + - name: "boundary_k_one_mixed" + in: + nums1: [-9, -4, 3, 8] + nums2: [-6, -2, 5, 7] + k: 1 + out: -63 + - name: "boundary_k_all" + in: + nums1: [-9, -4, 3, 8] + nums2: [-6, -2, 5, 7] + k: 16 + out: 56 + - name: "generated_full_positive" + in: + nums1: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: true + elemType: "int" + nums2: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: true + elemType: "int" + k: 1250000000 + seed: 204001 + - name: "generated_full_mixed" + in: + nums1: + gen: "array" + len: 50000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: true + elemType: "int" + nums2: + gen: "array" + len: 50000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: true + elemType: "int" + k: 1875000000 + seed: 204002 diff --git a/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/sol.py b/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/sol.py new file mode 100644 index 00000000..fe487687 --- /dev/null +++ b/tests/2001-2500/2040. kth-smallest-product-of-two-sorted-arrays/sol.py @@ -0,0 +1,36 @@ +class Solution: + def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int: + nums1.sort() + nums2.sort() + + def count_pairs(x: int) -> int: + count = 0 + for a in nums1: + if a > 0: + # a * b <= x => b <= x // a + count += bisect.bisect_right(nums2, x // a) + elif a < 0: + # a * b <= x => b >= ceil(x / a) + # careful with negatives + target = x // a + if x % a != 0: + target += 1 + count += len(nums2) - bisect.bisect_left(nums2, target) + else: + if x >= 0: + count += len(nums2) # zero * anything <= x + # else, 0 * any b > negative => contributes nothing + return count + + # Define search bounds + low = -10**10 + high = 10**10 + + while low < high: + mid = (low + high) // 2 + if count_pairs(mid) < k: + low = mid + 1 + else: + high = mid + + return low \ No newline at end of file diff --git a/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/manifest.yaml b/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/manifest.yaml new file mode 100644 index 00000000..e4e26321 --- /dev/null +++ b/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/manifest.yaml @@ -0,0 +1,192 @@ +entry: + id: 2042 + title: "check-if-numbers-are-ascending-in-a-sentence" + params: + s: + type: string + call: + cpp: "Solution().areNumbersAscending({s})" + rust: "Solution::are_numbers_ascending({s})" + python3: "Solution().areNumbersAscending({s})" + python2: "Solution().areNumbersAscending({s})" + ruby: "are_numbers_ascending({s})" + java: "new Solution().areNumbersAscending({s})" + csharp: "new Solution().AreNumbersAscending({s})" + kotlin: "Solution().areNumbersAscending({s})" + go: "areNumbersAscending({s})" + dart: "Solution().areNumbersAscending({s})" + swift: "Solution().areNumbersAscending({s})" + typescript: "areNumbersAscending({s})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().areNumbersAscending(s, {result})" + checker: | + class Checker: + def areNumbersAscending(self, s, result): + numbers = [int(token) for token in s.split(" ") if token.isdigit()] + expected = all(left < right for left, right in zip(numbers, numbers[1:])) + return result is expected + +seed: 2042 + +tests: + - name: "example_increasing" + in: + s: "1 box has 3 blue 4 red 6 green and 12 yellow marbles" + out: true + - name: "example_equal" + in: + s: "hello world 5 x 5" + out: false + - name: "example_decreasing" + in: + s: "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s" + out: false + - name: "two_numbers_increasing" + in: + s: "a 1 b 2" + out: true + - name: "two_numbers_decreasing" + in: + s: "a 2 b 1" + out: false + - name: "two_numbers_equal" + in: + s: "a 9 b 9" + out: false + - name: "minimum_number_one" + in: + s: "one 1 two 2" + out: true + - name: "maximum_number_ninety_nine" + in: + s: "one 98 two 99" + out: true + - name: "maximum_then_lower" + in: + s: "one 99 two 98" + out: false + - name: "numbers_not_at_edges" + in: + s: "alpha 4 beta gamma 17 delta" + out: true + - name: "all_words_between_numbers" + in: + s: "a 3 b c d 18 e f g 72 h" + out: true + - name: "decrease_at_start_pair" + in: + s: "a 20 b 19 c 80" + out: false + - name: "decrease_at_end_pair" + in: + s: "a 2 b 40 c 39" + out: false + - name: "equal_after_increase" + in: + s: "a 2 b 40 c 40" + out: false + - name: "equal_before_increase" + in: + s: "a 2 b 2 c 40" + out: false + - name: "strict_consecutive_values" + in: + s: "a 1 b 2 c 3 d 4" + out: true + - name: "wide_value_gaps" + in: + s: "a 1 b 50 c 99" + out: true + - name: "reverse_values" + in: + s: "a 99 b 50 c 1" + out: false + - name: "one_digit_sequence" + in: + s: "a 1 b 3 c 5 d 7 e 9" + out: true + - name: "mixed_digit_lengths" + in: + s: "a 2 b 10 c 11 d 90" + out: true + - name: "mixed_digit_lengths_decrease" + in: + s: "a 10 b 2 c 30" + out: false + - name: "numbers_adjacent" + in: + s: "a 1 2 3 b" + out: true + - name: "adjacent_equal" + in: + s: "a 1 2 2 b" + out: false + - name: "late_decrease_many_words" + in: + s: "the quick 3 brown fox 14 jumps over 28 the lazy dog 27 today" + out: false + - name: "increasing_many_words" + in: + s: "the quick 3 brown fox 14 jumps over 28 the lazy dog 35 today" + out: true + - name: "seven_numbers_increasing" + in: + s: "a 1 b 8 c 16 d 24 e 32 f 64 g 99 h" + out: true + - name: "seven_numbers_middle_equal" + in: + s: "a 1 b 8 c 16 d 16 e 32 f 64 g 99 h" + out: false + - name: "seven_numbers_middle_decrease" + in: + s: "a 1 b 8 c 16 d 15 e 32 f 64 g 99 h" + out: false + - name: "numbers_only_tokens" + in: + s: "1 2 3 4 5" + out: true + - name: "numbers_only_not_increasing" + in: + s: "1 2 4 3 5" + out: false + - name: "many_single_digit_numbers" + in: + s: "a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10" + out: true + - name: "many_single_digit_numbers_decrease" + in: + s: "a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 7 j 10" + out: false + - name: "boundary_1_2_99" + in: + s: "start 1 middle 2 finish 99" + out: true + - name: "boundary_1_99_1" + in: + s: "start 1 middle 99 finish 1" + out: false + - name: "long_words_valid" + in: + s: "aaaaaaaaaaaaaaaaaaaa 4 bbbbbbbbbbbbbbbbbbbb 25 cccccccccccccccccccc 76 dddddddddddddddddddd 98" + out: true + - name: "long_words_invalid" + in: + s: "aaaaaaaaaaaaaaaaaaaa 4 bbbbbbbbbbbbbbbbbbbb 25 cccccccccccccccccccc 76 dddddddddddddddddddd 75" + out: false + - name: "near_max_tokens_valid" + in: + s: "a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a 10 a 11 a 12 a 13 a 14 a 15 a 16 a 17 a 18 a 19 a 20 a 21 a 22 a 23 a 24 a 25 a 26 a 27 a 28 a 29 a 30 a 31 a 32 a 33 a 34 a 35 a 36 a 37 a 38 a 39 a 40 a 41 a 42 a 43 a 44 a 45 a 46 a 47 a 48 a 49 a 50 a 51 a 52 a 53 a 54 a 55 a 56 a 57 a 58 a 59 a 60 a 61 a 62 a 63 a 64 a 65 a 66 a 67 a 68 a 69 a 70 a 71 a 72 a 73 a 74 a 75 a 76 a 77 a 78 a 79 a 80 a 81 a 82 a 83 a 84 a 85 a 86 a 87 a 88 a 89 a 90 a 91 a 92 a 93 a 94 a 95 a 96 a 97 a 98 a 99" + out: true + - name: "near_max_tokens_invalid" + in: + s: "a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a 10 a 11 a 12 a 13 a 14 a 15 a 16 a 17 a 18 a 19 a 20 a 21 a 22 a 23 a 24 a 25 a 26 a 27 a 28 a 29 a 30 a 31 a 32 a 33 a 34 a 35 a 36 a 37 a 38 a 39 a 40 a 41 a 42 a 43 a 44 a 45 a 46 a 47 a 48 a 49 a 50 a 51 a 52 a 53 a 54 a 55 a 56 a 57 a 58 a 59 a 60 a 61 a 62 a 63 a 64 a 65 a 66 a 67 a 68 a 69 a 70 a 71 a 72 a 73 a 74 a 75 a 76 a 77 a 78 a 79 a 80 a 81 a 82 a 83 a 84 a 85 a 86 a 87 a 88 a 89 a 90 a 91 a 92 a 93 a 94 a 95 a 96 a 97 a 98 a 98" + out: false diff --git a/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/sol.py b/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/sol.py new file mode 100644 index 00000000..c3fdbd33 --- /dev/null +++ b/tests/2001-2500/2042. check-if-numbers-are-ascending-in-a-sentence/sol.py @@ -0,0 +1,13 @@ +class Solution: + def areNumbersAscending(self, s: str) -> bool: + s = s.split(" ") + count = -1 + for i in s: + if i.isdigit(): + if count == int(i): + return False + elif count > int(i): + return False + else: + count = int(i) + return True \ No newline at end of file diff --git a/tests/2001-2500/2043. simple-bank-system/sol.py b/tests/2001-2500/2043. simple-bank-system/sol.py new file mode 100644 index 00000000..06b14411 --- /dev/null +++ b/tests/2001-2500/2043. simple-bank-system/sol.py @@ -0,0 +1,27 @@ +class Solution: + class Bank: + def __init__(self, balance: list[int]): + self.bal = balance + self.n = len(balance) + + def valid(self, acc: int) -> bool: + return 1 <= acc <= self.n + + def transfer(self, account1: int, account2: int, money: int) -> bool: + if not self.valid(account1) or not self.valid(account2) or self.bal[account1 - 1] < money: + return False + self.bal[account1 - 1] -= money + self.bal[account2 - 1] += money + return True + + def deposit(self, account: int, money: int) -> bool: + if not self.valid(account): + return False + self.bal[account - 1] += money + return True + + def withdraw(self, account: int, money: int) -> bool: + if not self.valid(account) or self.bal[account - 1] < money: + return False + self.bal[account - 1] -= money + return True diff --git a/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/manifest.yaml b/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/manifest.yaml new file mode 100644 index 00000000..c4b6681f --- /dev/null +++ b/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/manifest.yaml @@ -0,0 +1,262 @@ +entry: + id: 2044 + title: "count-number-of-maximum-bitwise-or-subsets" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().countMaxOrSubsets({nums})" + rust: "Solution::count_max_or_subsets({nums})" + python3: "Solution().countMaxOrSubsets({nums})" + python2: "Solution().countMaxOrSubsets({nums})" + ruby: "count_max_or_subsets({nums})" + java: "new Solution().countMaxOrSubsets({nums})" + csharp: "new Solution().CountMaxOrSubsets({nums})" + kotlin: "Solution().countMaxOrSubsets({nums})" + go: "countMaxOrSubsets({nums})" + dart: "Solution().countMaxOrSubsets({nums})" + swift: "Solution().countMaxOrSubsets({nums})" + typescript: "countMaxOrSubsets({nums})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countMaxOrSubsets(nums, {result})" + checker: | + class Checker: + def countMaxOrSubsets(self, nums, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + target = 0 + for value in nums: + target |= value + count = 0 + for mask in range(1, 1 << len(nums)): + current = 0 + for index, value in enumerate(nums): + if mask & (1 << index): + current |= value + if current == target: + count += 1 + return result == count + +seed: 20442026 + +tests: + - name: "example_1" + in: + nums: [3, 1] + out: 2 + - name: "example_2_duplicates" + in: + nums: [2, 2, 2] + out: 7 + - name: "example_3" + in: + nums: [3, 2, 1, 5] + out: 6 + - name: "single_one" + in: + nums: [1] + out: 1 + - name: "single_large_value" + in: + nums: [100000] + out: 1 + - name: "two_equal_ones" + in: + nums: [1, 1] + out: 3 + - name: "two_disjoint_bits" + in: + nums: [1, 2] + out: 1 + - name: "four_equal_values" + in: + nums: [4, 4, 4, 4] + out: 15 + - name: "one_value_contains_all" + in: + nums: [7, 1, 2] + out: 4 + - name: "four_single_bits" + in: + nums: [8, 4, 2, 1] + out: 1 + - name: "overlapping_pair" + in: + nums: [5, 3] + out: 1 + - name: "duplicate_suffix" + in: + nums: [10, 5, 5] + out: 3 + - name: "five_disjoint_bits" + in: + nums: [16, 8, 4, 2, 1] + out: 1 + - name: "maximal_first_value" + in: + nums: [31, 1, 2, 4, 8, 16] + out: 33 + - name: "near_upper_bound_pair" + in: + nums: [100000, 99999] + out: 1 + - name: "three_overlapping_values" + in: + nums: [6, 10, 12] + out: 4 + - name: "five_equal_nines" + in: + nums: [9, 9, 9, 9, 9] + out: 31 + - name: "nested_prefix_values" + in: + nums: [1, 3, 7, 15] + out: 8 + - name: "four_disjoint_power_bits" + in: + nums: [2, 4, 8, 16] + out: 1 + - name: "three_shifted_values" + in: + nums: [17, 34, 68] + out: 1 + - name: "maximal_byte_value" + in: + nums: [255, 1, 2, 4] + out: 8 + - name: "one_dominant_bit" + in: + nums: [64, 64, 32, 16] + out: 3 + - name: "seven_bit_basis" + in: + nums: [63, 32, 16, 8, 4, 2, 1] + out: 65 + - name: "mixed_overlap_chain" + in: + nums: [12, 10, 6, 3] + out: 5 + - name: "large_sparse_values" + in: + nums: [99, 37, 18] + out: 1 + - name: "high_disjoint_bits" + in: + nums: [1024, 512, 256, 128] + out: 1 + - name: "small_mixed_values" + in: + nums: [1, 2, 3, 4, 5] + out: 17 + - name: "duplicate_groups" + in: + nums: [6, 6, 3, 3, 1] + out: 21 + - name: "descending_overlap" + in: + nums: [42, 21, 14, 7] + out: 4 + - name: "halving_upper_values" + in: + nums: [100000, 50000, 25000, 12500] + out: 2 + - name: "shifted_overlap_chain" + in: + nums: [11, 22, 44, 88] + out: 2 + - name: "eight_bit_basis" + in: + nums: [128, 64, 32, 16, 8, 4, 2, 1] + out: 1 + - name: "four_equal_full_masks" + in: + nums: [1023, 1023, 1023, 1023] + out: 15 + - name: "six_equal_ones" + in: + nums: [1, 1, 1, 1, 1, 1] + out: 63 + - name: "mixed_six_values" + in: + nums: [2, 3, 4, 5, 6] + out: 20 + - name: "generated_small_mixed" + seed: 101 + in: + nums: + gen: "array" + len: + gen: "int" + min: 1 + max: 8 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + - name: "generated_medium_values" + seed: 202 + in: + nums: + gen: "array" + len: + gen: "int" + min: 8 + max: 12 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + - name: "generated_max_length_random" + seed: 303 + in: + nums: + gen: "array" + len: 16 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + - name: "generated_max_length_duplicates" + seed: 404 + in: + nums: + gen: "array" + len: 16 + of: + gen: "int" + min: 1 + max: 15 + distinct: false + sorted: false + - name: "generated_long_sparse_range" + seed: 505 + in: + nums: + gen: "array" + len: + gen: "int" + min: 13 + max: 16 + of: + gen: "int" + min: 32768 + max: 100000 + distinct: false + sorted: false diff --git a/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/sol.py b/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/sol.py new file mode 100644 index 00000000..f9b6132b --- /dev/null +++ b/tests/2001-2500/2044. count-number-of-maximum-bitwise-or-subsets/sol.py @@ -0,0 +1,17 @@ +class Solution: + def countMaxOrSubsets(self, nums): + maxOR = 0 + for num in nums: + maxOR |= num + + def backtrack(index, currentOR): + if index == len(nums): + return 1 if currentOR == maxOR else 0 + + if currentOR == maxOR: + return 1 << (len(nums) - index) + + return backtrack(index + 1, currentOR | nums[index]) + \ + backtrack(index + 1, currentOR) + + return backtrack(0, 0) \ No newline at end of file diff --git a/tests/2001-2500/2045. second-minimum-time-to-reach-destination/manifest.yaml b/tests/2001-2500/2045. second-minimum-time-to-reach-destination/manifest.yaml new file mode 100644 index 00000000..88b79f16 --- /dev/null +++ b/tests/2001-2500/2045. second-minimum-time-to-reach-destination/manifest.yaml @@ -0,0 +1,419 @@ +entry: + id: 2045 + title: "second-minimum-time-to-reach-destination" + params: + n: + type: int + edges: + type: array + items: + type: array + items: + type: int + time: + type: int + change: + type: int + call: + cpp: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + rust: "Solution::second_minimum({n}, {edges}, {time}, {change})" + python3: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + python2: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + ruby: "second_minimum({n}, {edges}, {time}, {change})" + java: "new Solution().secondMinimum({n}, {edges}, {time}, {change})" + csharp: "new Solution().SecondMinimum({n}, {edges}, {time}, {change})" + kotlin: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + go: "secondMinimum({n}, {edges}, {time}, {change})" + dart: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + swift: "Solution().secondMinimum({n}, {edges}, {time}, {change})" + typescript: "secondMinimum({n}, {edges}, {time}, {change})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().secondMinimum(n, edges, time, change, {result})" + checker: | + class Checker: + def secondMinimum(self, n, edges, time, change, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + graph = [[] for _ in range(n + 1)] + for a, b in edges: + graph[a].append(b) + graph[b].append(a) + best = [[None, None] for _ in range(n + 1)] + best[1][0] = 0 + queue = [(0, 1)] + import heapq + while queue: + elapsed, node = heapq.heappop(queue) + if elapsed not in best[node]: + continue + for nxt in graph[node]: + depart = elapsed + if (depart // change) % 2: + depart = (depart // change + 1) * change + arrival = depart + time + if best[nxt][0] is None or arrival < best[nxt][0]: + best[nxt][1] = best[nxt][0] + best[nxt][0] = arrival + heapq.heappush(queue, (arrival, nxt)) + elif best[nxt][0] < arrival and (best[nxt][1] is None or arrival < best[nxt][1]): + best[nxt][1] = arrival + heapq.heappush(queue, (arrival, nxt)) + return result == best[n][1] + +seed: 2045 + +tests: + - name: "single_edge_unit_signals" + in: + n: 2 + edges: + - [1, 2] + time: 1 + change: 1 + out: 5 + - name: "single_edge_short_green_window" + in: + n: 2 + edges: + - [1, 2] + time: 1 + change: 2 + out: 5 + - name: "single_edge_even_travel" + in: + n: 2 + edges: + - [1, 2] + time: 2 + change: 1 + out: 6 + - name: "single_edge_equal_period" + in: + n: 2 + edges: + - [1, 2] + time: 2 + change: 2 + out: 10 + - name: "example_two" + in: + n: 2 + edges: + - [1, 2] + time: 3 + change: 2 + out: 11 + - name: "single_edge_wait_four" + in: + n: 2 + edges: + - [1, 2] + time: 5 + change: 3 + out: 17 + - name: "single_edge_long_edge_fast_signal" + in: + n: 2 + edges: + - [1, 2] + time: 10 + change: 1 + out: 30 + - name: "single_edge_long_period" + in: + n: 2 + edges: + - [1, 2] + time: 10 + change: 10 + out: 50 + - name: "path_three_unit" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + time: 1 + change: 1 + out: 7 + - name: "path_three_no_wait" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + time: 2 + change: 1 + out: 8 + - name: "path_three_boundary" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + time: 3 + change: 2 + out: 15 + - name: "path_three_long_period" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + time: 5 + change: 5 + out: 35 + - name: "path_four_short" + in: + n: 4 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + time: 1 + change: 2 + out: 9 + - name: "path_four_waiting" + in: + n: 4 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + time: 3 + change: 5 + out: 23 + - name: "path_five_mixed" + in: + n: 5 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + time: 2 + change: 3 + out: 16 + - name: "path_five_long_edge" + in: + n: 5 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + time: 7 + change: 4 + out: 47 + - name: "triangle_unit" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + - [1, 3] + time: 1 + change: 1 + out: 3 + - name: "triangle_wait" + in: + n: 3 + edges: + - [1, 2] + - [2, 3] + - [1, 3] + time: 4 + change: 3 + out: 10 + - name: "cycle_four_short" + in: + n: 4 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 1] + time: 2 + change: 2 + out: 10 + - name: "cycle_four_long" + in: + n: 4 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 1] + time: 5 + change: 3 + out: 17 + - name: "star_five_unit" + in: + n: 5 + edges: + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + time: 1 + change: 1 + out: 5 + - name: "star_five_wait" + in: + n: 5 + edges: + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + time: 4 + change: 2 + out: 12 + - name: "star_six_long_period" + in: + n: 6 + edges: + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + - [1, 6] + time: 3 + change: 5 + out: 13 + - name: "cycle_six" + in: + n: 6 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [1, 6] + time: 2 + change: 4 + out: 10 + - name: "cycle_with_chord" + in: + n: 6 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [1, 6] + - [2, 5] + time: 3 + change: 3 + out: 15 + - name: "cycle_seven_chord" + in: + n: 7 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [1, 7] + time: 6 + change: 7 + out: 20 + - name: "dense_five" + in: + n: 5 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [1, 3] + - [2, 4] + - [3, 5] + time: 8 + change: 6 + out: 32 + - name: "longer_sparse_chorded" + in: + n: 8 + edges: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [1, 8] + - [2, 7] + time: 9 + change: 4 + out: 27 + - name: "single_edge_green_boundary" + in: + n: 2 + edges: + - [1, 2] + time: 1 + change: 3 + out: 3 + - name: "single_edge_two_step_boundary" + in: + n: 2 + edges: + - [1, 2] + time: 2 + change: 3 + out: 8 + - name: "single_edge_red_boundary" + in: + n: 2 + edges: + - [1, 2] + time: 3 + change: 3 + out: 15 + - name: "single_edge_crossing_period" + in: + n: 2 + edges: + - [1, 2] + time: 4 + change: 3 + out: 16 + - name: "single_edge_multiple_periods" + in: + n: 2 + edges: + - [1, 2] + time: 7 + change: 3 + out: 21 + - name: "single_edge_change_five" + in: + n: 2 + edges: + - [1, 2] + time: 8 + change: 5 + out: 28 + - name: "single_edge_change_five_late" + in: + n: 2 + edges: + - [1, 2] + time: 9 + change: 5 + out: 29 diff --git a/tests/2001-2500/2045. second-minimum-time-to-reach-destination/sol.py b/tests/2001-2500/2045. second-minimum-time-to-reach-destination/sol.py new file mode 100644 index 00000000..506d09ca --- /dev/null +++ b/tests/2001-2500/2045. second-minimum-time-to-reach-destination/sol.py @@ -0,0 +1,39 @@ +class Solution: + def secondMinimum(self, n: int, edges: List[List[int]], time: int, change: int) -> int: + # build neighbors map + graph = [set() for _ in range(n + 1)] + for x, y in edges: + graph[x].add(y) + graph[y].add(x) + + # find the shortest paths length + curr = {1, } + visited = set() + answer = None + l = 0 + while not answer: + nxt = set() + for x in curr: + if x == n: + answer = l # found destination, but not breaking a loop to find second minimum + nxt |= graph[x] + nxt -= visited + + visited |= curr # add cities that we visited on previous step, not current one + curr = nxt + l += 1 + + if n in curr: # if we can reach destination on next move + answer += 1 + else: # if not we just revisit a city once in the shortest path + answer += 2 + + # convert path length to time + ttl = 0 + while answer: + phase = ttl % (change * 2) + if phase >= change: + ttl += (2 * change - phase) + ttl += time + answer -= 1 + return ttl \ No newline at end of file diff --git a/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/manifest.yaml b/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/manifest.yaml new file mode 100644 index 00000000..b81fdf3a --- /dev/null +++ b/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/manifest.yaml @@ -0,0 +1,229 @@ +entry: + id: 2047 + title: "number-of-valid-words-in-a-sentence" + params: + sentence: + type: string + call: + cpp: "Solution().countValidWords({sentence})" + rust: "Solution::count_valid_words({sentence})" + python3: "Solution().countValidWords({sentence})" + python2: "Solution().countValidWords({sentence})" + ruby: "count_valid_words({sentence})" + java: "new Solution().countValidWords({sentence})" + csharp: "new Solution().CountValidWords({sentence})" + kotlin: "Solution().countValidWords({sentence})" + go: "countValidWords({sentence})" + dart: "Solution().countValidWords({sentence})" + swift: "Solution().countValidWords({sentence})" + typescript: "countValidWords({sentence})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countValidWords(sentence, {result})" + checker: | + class Checker: + def countValidWords(self, sentence, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + total = 0 + for token in sentence.split(' '): + if not token: + continue + hyphens = 0 + punctuation = 0 + valid = True + for i, ch in enumerate(token): + if not ('a' <= ch <= 'z' or ch in '-!.,'): + valid = False + break + if ch == '-': + hyphens += 1 + if hyphens > 1 or i == 0 or i == len(token) - 1: + valid = False + break + if not ('a' <= token[i - 1] <= 'z' and 'a' <= token[i + 1] <= 'z'): + valid = False + break + elif ch in '!.,': + punctuation += 1 + if punctuation > 1 or i != len(token) - 1: + valid = False + break + if valid: + total += 1 + return result == total + +seed: 2047 + +tests: + - name: "example_one" + in: + sentence: "cat and dog" + out: 3 + - name: "example_two" + in: + sentence: "!this 1-s b8d!" + out: 0 + - name: "example_three" + in: + sentence: "alice and bob are playing stone-game10" + out: 5 + - name: "single_letter" + in: + sentence: "a" + out: 1 + - name: "single_digit" + in: + sentence: "7" + out: 0 + - name: "single_punctuation" + in: + sentence: "!" + out: 1 + - name: "single_hyphen" + in: + sentence: "-" + out: 0 + - name: "letters_with_period" + in: + sentence: "hello." + out: 1 + - name: "letters_with_comma" + in: + sentence: "hello," + out: 1 + - name: "letters_with_exclamation" + in: + sentence: "hello!" + out: 1 + - name: "hyphenated_word" + in: + sentence: "a-b" + out: 1 + - name: "hyphenated_with_punctuation" + in: + sentence: "a-b." + out: 1 + - name: "hyphen_at_start" + in: + sentence: "-ab" + out: 0 + - name: "hyphen_at_end" + in: + sentence: "ab-" + out: 0 + - name: "two_hyphens" + in: + sentence: "a-b-c" + out: 0 + - name: "hyphen_next_to_punctuation" + in: + sentence: "a-." + out: 0 + - name: "punctuation_at_start" + in: + sentence: ".abc" + out: 0 + - name: "punctuation_in_middle" + in: + sentence: "ab!cd" + out: 0 + - name: "two_punctuation_marks" + in: + sentence: "ab.," + out: 0 + - name: "digit_in_plain_word" + in: + sentence: "abc1" + out: 0 + - name: "digit_in_hyphenated_word" + in: + sentence: "a1-b" + out: 0 + - name: "mixed_valid_invalid" + in: + sentence: "a a-b a-b. a1 ab!cd ! good," + out: 5 + - name: "many_spaces" + in: + sentence: " a b-c d! " + out: 3 + - name: "all_invalid_forms" + in: + sentence: "1 1a a1 -a a- a--b a!b a.. a-," + out: 0 + - name: "all_valid_forms" + in: + sentence: "a ab abc a-b a-b! word, ! ." + out: 8 + - name: "long_plain_word" + in: + sentence: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + out: 1 + - name: "long_hyphenated_word" + in: + sentence: "abcdefghijklmnopqrstuv-wxyzabcdefghijklmnopqrstuv" + out: 1 + - name: "punctuation_variants" + in: + sentence: "a! b. c, ! . ," + out: 6 + - name: "hyphen_boundary_letters" + in: + sentence: "a-b ab-c abc-d x-y-z aa--bb" + out: 3 + - name: "invalid_punctuation_boundaries" + in: + sentence: "!a a!b a!b. a-, a,." + out: 0 + - name: "digits_and_valid_words" + in: + sentence: "room2 room two-words two-words! end." + out: 4 + - name: "repeated_valid_tokens" + in: + sentence: "ok ok ok! ok-ok ok-ok," + out: 5 + - name: "generated_small_alphabet" + seed: 11 + in: + sentence: + gen: "str" + len: 37 + alphabet: "ab-!1" + - name: "generated_medium_alphabet" + seed: 22 + in: + sentence: + gen: "str" + len: 251 + alphabet: "acm-.,2 " + - name: "generated_max_plain_symbols" + seed: 33 + in: + sentence: + gen: "str" + len: 1000 + alphabet: "abx-!0 " + - name: "generated_max_letters" + seed: 44 + in: + sentence: + gen: "str" + len: 1000 + alphabet: "adz" + - name: "generated_max_punctuation_mix" + seed: 55 + in: + sentence: + gen: "str" + len: 999 + alphabet: "qr-.!,3 " diff --git a/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/sol.py b/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/sol.py new file mode 100644 index 00000000..a2928707 --- /dev/null +++ b/tests/2001-2500/2047. number-of-valid-words-in-a-sentence/sol.py @@ -0,0 +1,39 @@ +class Solution: + def countValidWords(self, sentence: str) -> int: + def is_valid_word(token): + len_token = len(token) + + i = 0 + while (i < len_token): + c = token[i] + if (ord(c) not in range(ord('a'), ord('z') + 1) + and c != '-' + and c not in ('!', '.', ',')): + return False + elif (c == '-' + and i > 1 + and not token[:i].isalpha()): + return False + elif (c == '-' + and i < len_token - 1 + and (not token[i+1:].isalpha() and not (token[i+1:-1].isalpha() and token[-1] in ('!', '.', ',')))): + return False + elif (c == '-' + and (i == 0 or i == len_token-1)): + return False + elif (c in ('!', '.', ',') + and i < len_token - 1): + return False + + i += 1 + + return True + + tokens = [t for t in sentence.split(' ') if t != ''] + count_valid_words = 0 + for token in tokens: + print(token, is_valid_word(token)) + if (is_valid_word(token)): + count_valid_words += 1 + + return count_valid_words \ No newline at end of file diff --git a/tests/2001-2500/2048. next-greater-numerically-balanced-number/manifest.yaml b/tests/2001-2500/2048. next-greater-numerically-balanced-number/manifest.yaml new file mode 100644 index 00000000..289a8d6e --- /dev/null +++ b/tests/2001-2500/2048. next-greater-numerically-balanced-number/manifest.yaml @@ -0,0 +1,219 @@ +entry: + id: 2048 + title: "next-greater-numerically-balanced-number" + params: + n: + type: int + call: + cpp: "Solution().nextBeautifulNumber({n})" + rust: "Solution::next_beautiful_number({n})" + python3: "Solution().nextBeautifulNumber({n})" + python2: "Solution().nextBeautifulNumber({n})" + ruby: "next_beautiful_number({n})" + java: "new Solution().nextBeautifulNumber({n})" + csharp: "new Solution().NextBeautifulNumber({n})" + kotlin: "Solution().nextBeautifulNumber({n})" + go: "nextBeautifulNumber({n})" + dart: "Solution().nextBeautifulNumber({n})" + swift: "Solution().nextBeautifulNumber({n})" + typescript: "nextBeautifulNumber({n})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().nextBeautifulNumber(n, {result})" + checker: | + class Checker: + def nextBeautifulNumber(self, n, result): + if not isinstance(result, int) or result <= n: + return False + def balanced(x): + text = str(x) + return all(text.count(d) == int(d) for d in set(text)) + if not balanced(result): + return False + candidate = n + 1 + while candidate < result: + if balanced(candidate): + return False + candidate += 1 + return True + +seed: 2048 + +tests: + - name: "n_0" + in: + n: 0 + out: 1 + - name: "n_1" + in: + n: 1 + out: 22 + - name: "n_2" + in: + n: 2 + out: 22 + - name: "n_9" + in: + n: 9 + out: 22 + - name: "n_10" + in: + n: 10 + out: 22 + - name: "n_20" + in: + n: 20 + out: 22 + - name: "n_21" + in: + n: 21 + out: 22 + - name: "n_22" + in: + n: 22 + out: 122 + - name: "n_23" + in: + n: 23 + out: 122 + - name: "n_98" + in: + n: 98 + out: 122 + - name: "n_99" + in: + n: 99 + out: 122 + - name: "n_100" + in: + n: 100 + out: 122 + - name: "n_110" + in: + n: 110 + out: 122 + - name: "n_111" + in: + n: 111 + out: 122 + - name: "n_112" + in: + n: 112 + out: 122 + - name: "n_121" + in: + n: 121 + out: 122 + - name: "n_122" + in: + n: 122 + out: 212 + - name: "n_133" + in: + n: 133 + out: 212 + - name: "n_999" + in: + n: 999 + out: 1333 + - name: "n_1000" + in: + n: 1000 + out: 1333 + - name: "n_1001" + in: + n: 1001 + out: 1333 + - name: "n_1022" + in: + n: 1022 + out: 1333 + - name: "n_1023" + in: + n: 1023 + out: 1333 + - name: "n_1332" + in: + n: 1332 + out: 1333 + - name: "n_1333" + in: + n: 1333 + out: 3133 + - name: "n_1334" + in: + n: 1334 + out: 3133 + - name: "n_2122" + in: + n: 2122 + out: 3133 + - name: "n_2212" + in: + n: 2212 + out: 3133 + - name: "n_2221" + in: + n: 2221 + out: 3133 + - name: "n_2222" + in: + n: 2222 + out: 3133 + - name: "n_3000" + in: + n: 3000 + out: 3133 + - name: "n_3132" + in: + n: 3132 + out: 3133 + - name: "n_3133" + in: + n: 3133 + out: 3313 + - name: "n_3134" + in: + n: 3134 + out: 3313 + - name: "n_100000" + in: + n: 100000 + out: 122333 + - name: "n_999999" + in: + n: 999999 + out: 1224444 + - name: "n_1000000" + in: + n: 1000000 + out: 1224444 + - name: "generated_low" + seed: 101 + in: + n: + gen: "int" + min: 0 + max: 1000 + - name: "generated_mid" + seed: 202 + in: + n: + gen: "int" + min: 1001 + max: 100000 + - name: "generated_upper" + seed: 303 + in: + n: + gen: "int" + min: 900000 + max: 1000000 diff --git a/tests/2001-2500/2048. next-greater-numerically-balanced-number/sol.py b/tests/2001-2500/2048. next-greater-numerically-balanced-number/sol.py new file mode 100644 index 00000000..23e74c99 --- /dev/null +++ b/tests/2001-2500/2048. next-greater-numerically-balanced-number/sol.py @@ -0,0 +1,26 @@ +def generate(num: int, count: list[int], nums: list[int]) -> None: + if num > 0 and is_beautiful(count): + nums.append(num) + if num > 1224444: + return + + for d in range(1, 8): + if count[d] < d: + count[d] += 1 + generate(num * 10 + d, count, nums) + count[d] -= 1 + +def is_beautiful(count: list[int]) -> bool: + for d in range(1, 8): + if count[d] != 0 and count[d] != d: + return False + return True + +nums = [] +generate(0, [0]*10, nums) +nums.sort() + +class Solution: + def nextBeautifulNumber(self, n: int) -> int: + res = bisect_right(nums, n) + return nums[res] \ No newline at end of file diff --git a/tests/2001-2500/2049. count-nodes-with-the-highest-score/manifest.yaml b/tests/2001-2500/2049. count-nodes-with-the-highest-score/manifest.yaml new file mode 100644 index 00000000..a7d2b43c --- /dev/null +++ b/tests/2001-2500/2049. count-nodes-with-the-highest-score/manifest.yaml @@ -0,0 +1,209 @@ +entry: + id: 2049 + title: "count-nodes-with-the-highest-score" + params: + parents: + type: array + items: + type: int + call: + cpp: "Solution().countHighestScoreNodes({parents})" + rust: "Solution::count_highest_score_nodes({parents})" + python3: "Solution().countHighestScoreNodes({parents})" + python2: "Solution().countHighestScoreNodes({parents})" + ruby: "count_highest_score_nodes({parents})" + java: "new Solution().countHighestScoreNodes({parents})" + csharp: "new Solution().CountHighestScoreNodes({parents})" + kotlin: "Solution().countHighestScoreNodes({parents})" + go: "countHighestScoreNodes({parents})" + dart: "Solution().countHighestScoreNodes({parents})" + swift: "Solution().countHighestScoreNodes({parents})" + typescript: "countHighestScoreNodes({parents})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countHighestScoreNodes(parents, {result})" + checker: | + class Checker: + def countHighestScoreNodes(self, parents, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(parents) + children = [[] for _ in range(n)] + for i in range(1, n): + if not isinstance(parents[i], int) or parents[i] < 0 or parents[i] >= n: + return False + children[parents[i]].append(i) + if n < 3 or parents[0] != -1 or any(len(x) > 2 for x in children): + return False + sizes = [0] * n + scores = [0] * n + def dfs(node): + size = 1 + score = 1 + for child in children[node]: + child_size = dfs(child) + size += child_size + score *= child_size + if node != 0: + score *= n - size + sizes[node] = size + scores[node] = score + return size + dfs(0) + return result == sum(score == max(scores) for score in scores) + +seed: 2049 + +tests: + - name: "example_one" + in: + parents: [-1, 2, 0, 2, 0] + out: 3 + - name: "example_two" + in: + parents: [-1, 2, 0] + out: 2 + - name: "three_node_chain" + in: + parents: [-1, 0, 1] + out: 2 + - name: "three_node_star" + in: + parents: [-1, 0, 0] + out: 2 + - name: "four_node_chain" + in: + parents: [-1, 0, 1, 2] + out: 2 + - name: "four_node_starish" + in: + parents: [-1, 0, 0, 1] + out: 2 + - name: "four_node_balanced" + in: + parents: [-1, 0, 1, 1] + out: 3 + - name: "five_node_chain" + in: + parents: [-1, 0, 1, 2, 3] + out: 3 + - name: "five_node_star" + in: + parents: [-1, 0, 0, 0, 0] + out: 4 + - name: "five_node_split" + in: + parents: [-1, 0, 0, 1, 1] + out: 3 + - name: "six_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4] + out: 2 + - name: "six_node_two_level" + in: + parents: [-1, 0, 0, 1, 1, 2] + out: 1 + - name: "six_node_wide" + in: + parents: [-1, 0, 0, 0, 1, 2] + out: 3 + - name: "seven_node_perfect" + in: + parents: [-1, 0, 0, 1, 1, 2, 2] + out: 1 + - name: "seven_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5] + out: 1 + - name: "seven_node_left_heavy" + in: + parents: [-1, 0, 0, 1, 1, 3, 4] + out: 1 + - name: "eight_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6] + out: 2 + - name: "eight_node_balanced" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3] + out: 1 + - name: "eight_node_fan" + in: + parents: [-1, 0, 0, 0, 1, 1, 2, 2] + out: 1 + - name: "nine_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7] + out: 1 + - name: "nine_node_perfectish" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 4] + out: 1 + - name: "ten_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8] + out: 2 + - name: "ten_node_balanced" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4] + out: 1 + - name: "ten_node_bushy" + in: + parents: [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3] + out: 1 + - name: "eleven_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + out: 1 + - name: "twelve_node_completeish" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5] + out: 1 + - name: "twelve_node_bushy" + in: + parents: [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4] + out: 1 + - name: "thirteen_node_perfectish" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5] + out: 1 + - name: "fourteen_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + out: 2 + - name: "fifteen_node_perfect" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] + out: 2 + - name: "sixteen_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + out: 2 + - name: "seventeen_node_nearperfect" + in: + parents: [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8] + out: 1 + - name: "twenty_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] + out: 2 + - name: "twenty_node_bushy" + in: + parents: [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8] + out: 1 + - name: "twentyfive_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] + out: 1 + - name: "thirty_node_chain" + in: + parents: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28] + out: 2 diff --git a/tests/2001-2500/2049. count-nodes-with-the-highest-score/sol.py b/tests/2001-2500/2049. count-nodes-with-the-highest-score/sol.py new file mode 100644 index 00000000..ee74d059 --- /dev/null +++ b/tests/2001-2500/2049. count-nodes-with-the-highest-score/sol.py @@ -0,0 +1,36 @@ +class Solution(object): + def countHighestScoreNodes(self, parents): + """ + :type parents: List[int] + :rtype: int + """ + n = len(parents) + tree = [[] for _ in range(n)] + + for i in range(1, n): + tree[parents[i]].append(i) + + self.max_score = 0 + self.count = 0 + + def dfs(node): + score = 1 + size = 1 + for child in tree[node]: + subtree_size = dfs(child) + score *= subtree_size + size += subtree_size + + if node != 0: + score *= (n - size) + + if score > self.max_score: + self.max_score = score + self.count = 1 + elif score == self.max_score: + self.count += 1 + + return size + + dfs(0) + return self.count \ No newline at end of file diff --git a/tests/2001-2500/2050. parallel-courses-iii/manifest.yaml b/tests/2001-2500/2050. parallel-courses-iii/manifest.yaml new file mode 100644 index 00000000..785c9107 --- /dev/null +++ b/tests/2001-2500/2050. parallel-courses-iii/manifest.yaml @@ -0,0 +1,496 @@ +entry: + id: 2050 + title: "parallel-courses-iii" + params: + n: + type: int + relations: + type: array + items: + type: array + items: + type: int + time: + type: array + items: + type: int + call: + cpp: "Solution().minimumTime({n}, {relations}, {time})" + rust: "Solution::minimum_time({n}, {relations}, {time})" + python3: "Solution().minimumTime({n}, {relations}, {time})" + python2: "Solution().minimumTime({n}, {relations}, {time})" + ruby: "minimum_time({n}, {relations}, {time})" + java: "new Solution().minimumTime({n}, {relations}, {time})" + csharp: "new Solution().MinimumTime({n}, {relations}, {time})" + kotlin: "Solution().minimumTime({n}, {relations}, {time})" + go: "minimumTime({n}, {relations}, {time})" + dart: "Solution().minimumTime({n}, {relations}, {time})" + swift: "Solution().minimumTime({n}, {relations}, {time})" + typescript: "minimumTime({n}, {relations}, {time})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().minimumTime(n, relations, time, {result})" + checker: | + class Checker: + def minimumTime(self, n, relations, time, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + graph = [[] for _ in range(n)] + indegree = [0] * n + for u, v in relations: + graph[u - 1].append(v - 1) + indegree[v - 1] += 1 + finish = list(time) + queue = [i for i in range(n) if indegree[i] == 0] + head = 0 + while head < len(queue): + u = queue[head] + head += 1 + for v in graph[u]: + finish[v] = max(finish[v], finish[u] + time[v]) + indegree[v] -= 1 + if indegree[v] == 0: + queue.append(v) + return result == max(finish) + +seed: 2050 + +tests: + - name: "example_one_join" + in: + n: 3 + relations: + - [1, 3] + - [2, 3] + time: [3, 2, 5] + out: 8 + - name: "example_two_nested_join" + in: + n: 5 + relations: + - [1, 5] + - [2, 5] + - [3, 5] + - [3, 4] + - [4, 5] + time: [1, 2, 3, 4, 5] + out: 12 + - name: "single_course_minimum" + in: + n: 1 + relations: [] + time: [1] + out: 1 + - name: "single_course_maximum" + in: + n: 1 + relations: [] + time: [10000] + out: 10000 + - name: "two_independent_courses" + in: + n: 2 + relations: [] + time: [7, 3] + out: 7 + - name: "two_course_chain" + in: + n: 2 + relations: + - [1, 2] + time: [4, 9] + out: 13 + - name: "three_course_chain" + in: + n: 3 + relations: + - [1, 2] + - [2, 3] + time: [2, 5, 8] + out: 15 + - name: "chain_all_max_time" + in: + n: 5 + relations: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + time: [10000, 10000, 10000, 10000, 10000] + out: 50000 + - name: "wide_fan_out" + in: + n: 6 + relations: + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + - [1, 6] + time: [6, 1, 9, 3, 8, 2] + out: 15 + - name: "wide_fan_in" + in: + n: 6 + relations: + - [1, 6] + - [2, 6] + - [3, 6] + - [4, 6] + - [5, 6] + time: [6, 1, 9, 3, 8, 2] + out: 11 + - name: "disconnected_long_component" + in: + n: 6 + relations: + - [1, 2] + - [2, 3] + - [4, 5] + time: [4, 6, 5, 20, 1, 2] + out: 21 + - name: "critical_path_not_longest_node_count" + in: + n: 6 + relations: + - [1, 2] + - [2, 3] + - [3, 6] + - [4, 5] + - [5, 6] + time: [2, 2, 2, 20, 20, 1] + out: 41 + - name: "late_heavy_leaf" + in: + n: 4 + relations: + - [1, 2] + - [2, 3] + - [1, 4] + time: [3, 4, 1, 10000] + out: 10003 + - name: "multiple_predecessor_max_selection" + in: + n: 5 + relations: + - [1, 4] + - [2, 4] + - [3, 4] + - [4, 5] + time: [1, 50, 2, 3, 4] + out: 57 + - name: "diamond_equal_paths" + in: + n: 4 + relations: + - [1, 2] + - [1, 3] + - [2, 4] + - [3, 4] + time: [5, 2, 2, 7] + out: 14 + - name: "diamond_unequal_paths" + in: + n: 4 + relations: + - [1, 2] + - [1, 3] + - [2, 4] + - [3, 4] + time: [5, 20, 2, 7] + out: 32 + - name: "complete_dag_four" + in: + n: 4 + relations: + - [1, 2] + - [1, 3] + - [1, 4] + - [2, 3] + - [2, 4] + - [3, 4] + time: [3, 1, 10, 2] + out: 16 + - name: "transitive_edges" + in: + n: 5 + relations: + - [1, 2] + - [1, 3] + - [1, 5] + - [2, 3] + - [2, 4] + - [3, 4] + - [3, 5] + - [4, 5] + time: [2, 3, 4, 5, 6] + out: 20 + - name: "zero_relations_varied_times" + in: + n: 8 + relations: [] + time: [1, 100, 2, 99, 3, 98, 4, 97] + out: 100 + - name: "ordering_independent_of_input_order" + in: + n: 5 + relations: + - [4, 5] + - [2, 4] + - [1, 3] + - [3, 5] + - [1, 2] + time: [6, 2, 9, 1, 4] + out: 19 + - name: "parallel_sources_then_chain" + in: + n: 7 + relations: + - [1, 4] + - [2, 4] + - [3, 5] + - [4, 6] + - [5, 6] + - [6, 7] + time: [8, 3, 10, 2, 4, 6, 1] + out: 21 + - name: "heavy_source_parallel_branches" + in: + n: 6 + relations: + - [1, 2] + - [1, 3] + - [2, 4] + - [3, 5] + - [4, 6] + - [5, 6] + time: [30, 1, 20, 1, 2, 5] + out: 57 + - name: "five_level_mixed_dag" + in: + n: 9 + relations: + - [1, 4] + - [2, 4] + - [2, 5] + - [3, 5] + - [4, 6] + - [5, 6] + - [5, 7] + - [6, 8] + - [7, 8] + - [8, 9] + time: [3, 7, 2, 5, 11, 4, 6, 3, 8] + out: 35 + - name: "isolated_maximum" + in: + n: 5 + relations: + - [1, 2] + - [2, 3] + time: [2, 2, 2, 9999, 1] + out: 9999 + - name: "all_courses_one_level" + in: + n: 10 + relations: [] + time: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] + out: 100 + - name: "long_chain_six" + in: + n: 6 + relations: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + time: [1, 10, 1, 10, 1, 10] + out: 33 + - name: "two_chains_join" + in: + n: 8 + relations: + - [1, 2] + - [2, 3] + - [4, 5] + - [5, 6] + - [3, 7] + - [6, 7] + - [7, 8] + time: [2, 3, 4, 10, 1, 1, 5, 2] + out: 19 + - name: "wide_then_deep" + in: + n: 10 + relations: + - [1, 3] + - [1, 4] + - [1, 5] + - [2, 3] + - [2, 4] + - [2, 5] + - [3, 6] + - [4, 7] + - [5, 8] + - [6, 9] + - [7, 9] + - [8, 10] + time: [4, 6, 2, 9, 3, 5, 1, 20, 2, 1] + out: 30 + - name: "dense_dag_six" + in: + n: 6 + relations: + - [1, 2] + - [1, 3] + - [1, 4] + - [1, 5] + - [1, 6] + - [2, 3] + - [2, 4] + - [2, 5] + - [2, 6] + - [3, 4] + - [3, 5] + - [3, 6] + - [4, 5] + - [4, 6] + - [5, 6] + time: [2, 4, 1, 8, 2, 3] + out: 20 + - name: "large_chain_fifty" + in: + n: 50 + relations: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + - [9, 10] + - [10, 11] + - [11, 12] + - [12, 13] + - [13, 14] + - [14, 15] + - [15, 16] + - [16, 17] + - [17, 18] + - [18, 19] + - [19, 20] + - [20, 21] + - [21, 22] + - [22, 23] + - [23, 24] + - [24, 25] + - [25, 26] + - [26, 27] + - [27, 28] + - [28, 29] + - [29, 30] + - [30, 31] + - [31, 32] + - [32, 33] + - [33, 34] + - [34, 35] + - [35, 36] + - [36, 37] + - [37, 38] + - [38, 39] + - [39, 40] + - [40, 41] + - [41, 42] + - [42, 43] + - [43, 44] + - [44, 45] + - [45, 46] + - [46, 47] + - [47, 48] + - [48, 49] + - [49, 50] + time: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50] + out: 1275 + - name: "large_parallel_fifteen" + in: + n: 15 + relations: + - [1, 15] + - [2, 15] + - [3, 15] + - [4, 15] + - [5, 15] + - [6, 15] + - [7, 15] + - [8, 15] + - [9, 15] + - [10, 15] + - [11, 15] + - [12, 15] + - [13, 15] + - [14, 15] + time: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 10000] + out: 10014 + - name: "single_heavy_course_after_sources" + in: + n: 5 + relations: + - [1, 5] + - [2, 5] + - [3, 5] + - [4, 5] + time: [10000, 9999, 9998, 9997, 1] + out: 10001 + - name: "branch_rejoins_twice" + in: + n: 8 + relations: + - [1, 2] + - [1, 3] + - [2, 4] + - [3, 5] + - [4, 6] + - [5, 6] + - [6, 7] + - [6, 8] + time: [1, 4, 10, 2, 1, 3, 8, 2] + out: 23 + - name: "several_disconnected_components" + in: + n: 9 + relations: + - [1, 2] + - [2, 3] + - [4, 5] + - [6, 7] + - [7, 8] + - [8, 9] + time: [3, 4, 5, 100, 1, 2, 2, 2, 2] + out: 101 + - name: "long_path_with_shortcuts" + in: + n: 7 + relations: + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [1, 4] + - [2, 5] + - [3, 6] + - [4, 7] + time: [5, 1, 10, 2, 9, 1, 6] + out: 34 diff --git a/tests/2001-2500/2050. parallel-courses-iii/sol.py b/tests/2001-2500/2050. parallel-courses-iii/sol.py new file mode 100644 index 00000000..71bfeec2 --- /dev/null +++ b/tests/2001-2500/2050. parallel-courses-iii/sol.py @@ -0,0 +1,48 @@ +from collections import deque + +class Solution: + def minimumTime(self, n: int, + relations: List[List[int]], + time: List[int]) -> int: + + ans = 0 + + indegree = [0] * (n + 1) + completionTime = [0] * (n + 1) + + adj = [[] for _ in range(n + 1)] + + # Build graph + for u, v in relations: + indegree[v] += 1 + adj[u].append(v) + + q = deque() + + # Push nodes having indegree 0 + for i in range(1, n + 1): + if indegree[i] == 0: + q.append(i) + + # Kahn's Algorithm + DP + while q: + node = q.popleft() + + for neigh in adj[node]: + + indegree[neigh] -= 1 + + completionTime[neigh] = max( + completionTime[neigh], + completionTime[node] + time[node - 1] + ) + + if indegree[neigh] == 0: + q.append(neigh) + + # Final answer + for i in range(1, n + 1): + ans = max(ans, + completionTime[i] + time[i - 1]) + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2053. kth-distinct-string-in-an-array/manifest.yaml b/tests/2001-2500/2053. kth-distinct-string-in-an-array/manifest.yaml new file mode 100644 index 00000000..43d84961 --- /dev/null +++ b/tests/2001-2500/2053. kth-distinct-string-in-an-array/manifest.yaml @@ -0,0 +1,277 @@ +entry: + id: 2053 + title: "kth-distinct-string-in-an-array" + params: + arr: + type: array + items: + type: string + k: + type: int + call: + cpp: "Solution().kthDistinct({arr}, {k})" + rust: "Solution::kth_distinct({arr}, {k})" + python3: "Solution().kthDistinct({arr}, {k})" + python2: "Solution().kthDistinct({arr}, {k})" + ruby: "kth_distinct({arr}, {k})" + java: "new Solution().kthDistinct({arr}, {k})" + csharp: "new Solution().KthDistinct({arr}, {k})" + kotlin: "Solution().kthDistinct({arr}, {k})" + go: "kthDistinct({arr}, {k})" + dart: "Solution().kthDistinct({arr}, {k})" + swift: "Solution().kthDistinct({arr}, {k})" + typescript: "kthDistinct({arr}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 256 + +oracle: + python3: + call: "Checker().kthDistinct(arr, k, {result})" + checker: | + class Checker: + def kthDistinct(self, arr, k, result): + counts = {} + for value in arr: + counts[value] = counts.get(value, 0) + 1 + distinct = [value for value in arr if counts[value] == 1] + expected = distinct[k - 1] if k <= len(distinct) else "" + return result == expected + +seed: 2053 + +tests: + - name: "example_ordered_duplicates" + in: + arr: ["d", "b", "c", "b", "c", "a"] + k: 2 + out: "a" + - name: "example_all_distinct" + in: + arr: ["aaa", "aa", "a"] + k: 1 + out: "aaa" + - name: "example_not_enough" + in: + arr: ["a", "b", "a"] + k: 3 + out: "" + - name: "single_element_first" + in: + arr: ["z"] + k: 1 + out: "z" + - name: "single_element_impossible" + in: + arr: ["z"] + k: 1 + out: "z" + - name: "two_distinct_first" + in: + arr: ["a", "b"] + k: 2 + out: "b" + - name: "two_equal" + in: + arr: ["a", "a"] + k: 2 + out: "" + - name: "duplicate_first_unique_later" + in: + arr: ["x", "x", "y", "z"] + k: 1 + out: "y" + - name: "unique_after_repeated_prefix" + in: + arr: ["a", "b", "a", "b", "c"] + k: 1 + out: "c" + - name: "unique_after_repeated_prefix_second" + in: + arr: ["a", "b", "a", "b", "c", "d"] + k: 2 + out: "d" + - name: "repeated_middle_preserves_order" + in: + arr: ["m", "n", "m", "o", "p", "n", "q"] + k: 3 + out: "q" + - name: "all_unique_last" + in: + arr: ["a", "b", "c", "d", "e"] + k: 5 + out: "e" + - name: "all_unique_middle" + in: + arr: ["a", "b", "c", "d", "e"] + k: 3 + out: "c" + - name: "all_repeated" + in: + arr: ["abc", "abc", "abc", "abc"] + k: 1 + out: "" + - name: "one_unique_at_end" + in: + arr: ["aa", "bb", "aa", "bb", "cc"] + k: 1 + out: "cc" + - name: "one_unique_at_start" + in: + arr: ["cc", "aa", "bb", "aa", "bb"] + k: 1 + out: "cc" + - name: "unique_strings_length_five" + in: + arr: ["abcde", "bcdea", "cdeab"] + k: 2 + out: "bcdea" + - name: "case_sensitive_lowercase_only" + in: + arr: ["a", "aa", "a", "aaa", "aa", "aaaa"] + k: 2 + out: "aaaa" + - name: "k_equals_array_length_with_one_unique" + in: + arr: ["p", "p", "p", "q"] + k: 4 + out: "" + - name: "k_equals_array_length_all_unique" + in: + arr: ["p", "q", "r", "s"] + k: 4 + out: "s" + - name: "alternating_pairs" + in: + arr: ["a", "b", "c", "a", "b", "d", "e"] + k: 2 + out: "d" + - name: "alternating_pairs_first_unique" + in: + arr: ["a", "b", "c", "a", "b", "d", "e"] + k: 1 + out: "c" + - name: "long_value_unique" + in: + arr: ["zzzzz", "aaaaa", "zzzzz", "yyyyy", "xxxxx"] + k: 2 + out: "yyyyy" + - name: "long_value_first" + in: + arr: ["zzzzz", "aaaaa", "zzzzz", "yyyyy", "xxxxx"] + k: 1 + out: "aaaaa" + - name: "all_unique_length_one" + in: + arr: ["a", "b", "c", "d", "e", "f"] + k: 6 + out: "f" + - name: "duplicates_hide_two_values" + in: + arr: ["a", "b", "c", "b", "d", "c", "e", "a", "f"] + k: 2 + out: "e" + - name: "duplicates_hide_two_values_last" + in: + arr: ["a", "b", "c", "b", "d", "c", "e", "a", "f"] + k: 3 + out: "f" + - name: "no_distinct_with_many_duplicates" + in: + arr: ["a", "b", "c", "a", "b", "c", "a", "b", "c"] + k: 1 + out: "" + - name: "unique_order_not_lexical" + in: + arr: ["z", "y", "x", "z", "w", "y"] + k: 2 + out: "w" + - name: "unique_order_not_lexical_second" + in: + arr: ["z", "y", "x", "z", "w", "y"] + k: 3 + out: "" + - name: "max_length_all_unique" + in: + arr: ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee", "fffff", "ggggg", "hhhhh", "iiiii", "jjjjj"] + k: 10 + out: "jjjjj" + - name: "generated_small_mixed" + in: + arr: + gen: "array" + len: 25 + of: + gen: "str" + len: 2 + alphabet: "abcd" + distinct: false + elemType: "string" + k: + gen: "int" + min: 1 + max: 25 + - name: "generated_medium_mixed" + in: + arr: + gen: "array" + len: 120 + of: + gen: "str" + len: 3 + alphabet: "abcde" + distinct: false + elemType: "string" + k: + gen: "int" + min: 1 + max: 120 + - name: "generated_long_values" + in: + arr: + gen: "array" + len: 300 + of: + gen: "str" + len: 5 + alphabet: "abcdef" + distinct: false + elemType: "string" + k: + gen: "int" + min: 1 + max: 300 + - name: "generated_near_maximum" + in: + arr: + gen: "array" + len: 900 + of: + gen: "str" + len: 5 + alphabet: "abcdefgh" + distinct: false + elemType: "string" + k: + gen: "int" + min: 1 + max: 900 + - name: "generated_maximum" + in: + arr: + gen: "array" + len: 1000 + of: + gen: "str" + len: 5 + alphabet: "abcdefghij" + distinct: false + elemType: "string" + k: + gen: "int" + min: 1 + max: 1000 diff --git a/tests/2001-2500/2053. kth-distinct-string-in-an-array/sol.py b/tests/2001-2500/2053. kth-distinct-string-in-an-array/sol.py new file mode 100644 index 00000000..67ef4c36 --- /dev/null +++ b/tests/2001-2500/2053. kth-distinct-string-in-an-array/sol.py @@ -0,0 +1,16 @@ +class Solution: + def kthDistinct(self, arr, k): + n=len(arr) + vec=[] + for i in range(n): + t=0 + for j in range(n): + if i!=j and arr[i]==arr[j]: + break + elif i!=j and arr[i]!=arr[j]: + t+=1 + if t==n-1: + vec.append(arr[i]) + if len(vec) <= k-1: + return "" + return vec[k-1] \ No newline at end of file diff --git a/tests/2001-2500/2054. two-best-non-overlapping-events/manifest.yaml b/tests/2001-2500/2054. two-best-non-overlapping-events/manifest.yaml new file mode 100644 index 00000000..9084ac63 --- /dev/null +++ b/tests/2001-2500/2054. two-best-non-overlapping-events/manifest.yaml @@ -0,0 +1,397 @@ +entry: + id: 2054 + title: "two-best-non-overlapping-events" + params: + events: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().maxTwoEvents({events})" + rust: "Solution::max_two_events({events})" + python3: "Solution().maxTwoEvents({events})" + python2: "Solution().maxTwoEvents({events})" + ruby: "max_two_events({events})" + java: "new Solution().maxTwoEvents({events})" + csharp: "new Solution().MaxTwoEvents({events})" + kotlin: "Solution().maxTwoEvents({events})" + go: "maxTwoEvents({events})" + dart: "Solution().maxTwoEvents({events})" + swift: "Solution().maxTwoEvents({events})" + typescript: "maxTwoEvents({events})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maxTwoEvents(events, {result})" + checker: | + class Checker: + def maxTwoEvents(self, events, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + ordered = sorted(events, key=lambda x: x[1]) + starts = sorted(events, key=lambda x: x[0]) + best = 0 + answer = 0 + j = 0 + for start, end, value in starts: + while j < len(ordered) and ordered[j][1] < start: + best = max(best, ordered[j][2]) + j += 1 + answer = max(answer, value, value + best) + return result == answer + +seed: 20542026 + +tests: + - name: "example_1" + in: + events: + elemType: "int" + value: + - [1, 3, 2] + - [4, 5, 2] + - [2, 4, 3] + out: 4 + - name: "example_2" + in: + events: + elemType: "int" + value: + - [1, 3, 2] + - [4, 5, 2] + - [1, 5, 5] + out: 5 + - name: "example_3" + in: + events: + elemType: "int" + value: + - [1, 5, 3] + - [1, 5, 1] + - [6, 6, 5] + out: 8 + - name: "minimum_two_events" + in: + events: + elemType: "int" + value: + - [1, 1, 7] + - [2, 2, 9] + out: 16 + - name: "single_best_overlap" + in: + events: + elemType: "int" + value: + - [1, 10, 100] + - [2, 3, 4] + - [4, 5, 5] + out: 100 + - name: "same_endpoint_is_overlap" + in: + events: + elemType: "int" + value: + - [1, 3, 8] + - [3, 4, 100] + - [5, 6, 1] + out: 101 + - name: "adjacent_is_allowed" + in: + events: + elemType: "int" + value: + - [1, 3, 8] + - [4, 4, 100] + - [5, 8, 2] + out: 108 + - name: "all_identical_intervals" + in: + events: + elemType: "int" + value: + - [10, 20, 4] + - [10, 20, 9] + - [10, 20, 7] + - [10, 20, 6] + out: 9 + - name: "nested_intervals" + in: + events: + elemType: "int" + value: + - [1, 100, 50] + - [2, 10, 20] + - [11, 12, 30] + - [13, 99, 40] + out: 70 + - name: "best_prefix_then_suffix" + in: + events: + elemType: "int" + value: + - [1, 2, 20] + - [3, 10, 1] + - [11, 12, 30] + - [13, 14, 2] + out: 50 + - name: "best_suffix_only" + in: + events: + elemType: "int" + value: + - [1, 10, 3] + - [2, 9, 4] + - [11, 12, 90] + - [13, 14, 2] + out: 94 + - name: "unsorted_input" + in: + events: + elemType: "int" + value: + - [20, 25, 8] + - [1, 2, 11] + - [10, 12, 7] + - [3, 9, 10] + out: 21 + - name: "large_values" + in: + events: + elemType: "int" + value: + - [1, 1, 1000000] + - [2, 2, 1000000] + - [3, 1000000000, 999999] + out: 2000000 + - name: "large_times" + in: + events: + elemType: "int" + value: + - [999999998, 999999998, 12] + - [999999999, 1000000000, 100] + - [1, 1, 50] + out: 150 + - name: "one_point_events" + in: + events: + elemType: "int" + value: + - [5, 5, 3] + - [6, 6, 4] + - [7, 7, 8] + - [5, 5, 20] + out: 28 + - name: "many_ties" + in: + events: + elemType: "int" + value: + - [1, 2, 5] + - [1, 2, 6] + - [3, 4, 7] + - [3, 4, 8] + - [5, 6, 9] + out: 17 + - name: "long_gap" + in: + events: + elemType: "int" + value: + - [1, 2, 1] + - [100, 200, 2] + - [1000, 2000, 300] + out: 302 + - name: "overlap_chain" + in: + events: + elemType: "int" + value: + - [1, 4, 10] + - [2, 5, 20] + - [3, 6, 30] + - [7, 8, 4] + out: 34 + - name: "contained_high_value" + in: + events: + elemType: "int" + value: + - [1, 10, 5] + - [2, 3, 100] + - [4, 5, 6] + - [11, 12, 7] + out: 107 + - name: "equal_start_different_end" + in: + events: + elemType: "int" + value: + - [5, 5, 2] + - [5, 8, 50] + - [9, 9, 60] + out: 110 + - name: "equal_end_different_start" + in: + events: + elemType: "int" + value: + - [1, 5, 2] + - [4, 5, 80] + - [6, 7, 9] + out: 89 + - name: "best_two_of_three" + in: + events: + elemType: "int" + value: + - [1, 2, 15] + - [3, 4, 14] + - [5, 6, 13] + - [2, 5, 100] + out: 100 + - name: "zero_gap_boundary" + in: + events: + elemType: "int" + value: + - [10, 10, 10] + - [11, 11, 20] + - [12, 12, 30] + out: 50 + - name: "two_disjoint_pairs" + in: + events: + elemType: "int" + value: + - [1, 2, 40] + - [3, 4, 1] + - [10, 11, 39] + - [12, 13, 38] + out: 79 + - name: "high_middle_event" + in: + events: + elemType: "int" + value: + - [1, 3, 10] + - [4, 6, 11] + - [2, 5, 100] + - [7, 8, 1] + out: 101 + - name: "far_coordinate_mix" + in: + events: + elemType: "int" + value: + - [1, 100, 1] + - [101, 200, 2] + - [201, 300, 4] + - [301, 1000000000, 8] + out: 12 + - name: "duplicate_best_values" + in: + events: + elemType: "int" + value: + - [1, 1, 25] + - [2, 2, 25] + - [1, 2, 50] + - [3, 3, 1] + out: 51 + - name: "strictly_increasing_nonoverlap" + in: + events: + elemType: "int" + value: + - [1, 1, 1] + - [2, 2, 2] + - [3, 3, 4] + - [4, 4, 8] + - [5, 5, 16] + out: 24 + - name: "strictly_overlapping" + in: + events: + elemType: "int" + value: + - [1, 100, 1] + - [2, 99, 2] + - [3, 98, 3] + - [4, 97, 100] + out: 100 + - name: "large_sum_boundary" + in: + events: + elemType: "int" + value: + - [1, 1, 999999] + - [2, 2, 999998] + - [3, 3, 999997] + out: 1999997 + - name: "dense_valid_intervals" + in: + events: + elemType: "int" + value: + - [1, 2, 3] + - [2, 4, 20] + - [3, 5, 19] + - [4, 6, 18] + - [5, 7, 17] + - [6, 8, 16] + - [7, 9, 15] + - [8, 10, 14] + - [9, 11, 13] + - [10, 12, 12] + out: 37 + - name: "coordinate_extremes_pair" + in: + events: + elemType: "int" + value: + - [1, 1, 1] + - [2, 1000000000, 1000000] + - [1000000000, 1000000000, 999999] + out: 1000001 + - name: "late_pair_beats_early_pair" + in: + events: + elemType: "int" + value: + - [1, 10, 10] + - [11, 20, 11] + - [21, 30, 12] + - [31, 40, 100] + out: 112 + - name: "all_events_touching" + in: + events: + elemType: "int" + value: + - [1, 2, 5] + - [2, 3, 50] + - [3, 4, 500] + - [4, 5, 5000] + - [5, 6, 50000] + out: 50500 + - name: "short_event_outweighs_long_event" + in: + events: + elemType: "int" + value: + - [1, 100, 8] + - [1, 1, 20] + - [101, 101, 21] + - [50, 60, 100] + out: 121 diff --git a/tests/2001-2500/2054. two-best-non-overlapping-events/sol.py b/tests/2001-2500/2054. two-best-non-overlapping-events/sol.py new file mode 100644 index 00000000..dc35c568 --- /dev/null +++ b/tests/2001-2500/2054. two-best-non-overlapping-events/sol.py @@ -0,0 +1,17 @@ +class Solution: + def maxTwoEvents(self, events: List[List[int]]) -> int: + + end_sorted = deque(sorted(events, key=itemgetter(1))) + start_sorted = sorted(events, key=itemgetter(0)) + + ans = max(v for _, _, v in events) + + end_max = 0 + + for start, end, value in start_sorted: + while end_sorted and end_sorted[0][1] < start: + _, _, v = end_sorted.popleft() + end_max = max(end_max, v) + ans = max(ans, value + end_max) + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2055. plates-between-candles/manifest.yaml b/tests/2001-2500/2055. plates-between-candles/manifest.yaml new file mode 100644 index 00000000..84c172ce --- /dev/null +++ b/tests/2001-2500/2055. plates-between-candles/manifest.yaml @@ -0,0 +1,296 @@ +entry: + id: 2055 + title: "plates-between-candles" + params: + s: + type: string + queries: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().platesBetweenCandles({s}, {queries})" + rust: "Solution::plates_between_candles({s}, {queries})" + python3: "Solution().platesBetweenCandles({s}, {queries})" + python2: "Solution().platesBetweenCandles({s}, {queries})" + ruby: "plates_between_candles({s}, {queries})" + java: "new Solution().platesBetweenCandles({s}, {queries})" + csharp: "new Solution().PlatesBetweenCandles({s}, {queries})" + kotlin: "Solution().platesBetweenCandles({s}, {queries})" + go: "platesBetweenCandles({s}, {queries})" + dart: "Solution().platesBetweenCandles({s}, {queries})" + swift: "Solution().platesBetweenCandles({s}, {queries})" + typescript: "platesBetweenCandles({s}, {queries})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 512 + +oracle: + python3: + call: "Checker().platesBetweenCandles(s, queries, {result})" + checker: | + class Checker: + def platesBetweenCandles(self, s, queries, result): + if not isinstance(result, list) or len(result) != len(queries): + return False + expected = [] + for left, right in queries: + candles = [i for i in range(left, right + 1) if s[i] == '|'] + if len(candles) < 2: + expected.append(0) + else: + expected.append(sum(1 for ch in s[candles[0] + 1:candles[-1]] if ch == '*')) + return result == expected + +seed: 2055 + +tests: + - name: "example_one" + in: + s: "**|**|***|" + queries: [[2, 5], [5, 9]] + out: [2, 3] + - name: "example_two" + in: + s: "***|**|*****|**||**|*" + queries: [[1, 17], [4, 5], [14, 17], [5, 11], [15, 16]] + out: [9, 0, 0, 0, 0] + - name: "all_plates" + in: + s: "******" + queries: [[0, 5], [1, 1], [2, 4]] + out: [0, 0, 0] + - name: "all_candles" + in: + s: "||||||" + queries: [[0, 5], [1, 4], [3, 3]] + out: [0, 0, 0] + - name: "one_inner_plate" + in: + s: "|*|" + queries: [[0, 2], [0, 1], [1, 2]] + out: [1, 0, 0] + - name: "adjacent_candles" + in: + s: "|*||*|" + queries: [[0, 5], [2, 5], [2, 3]] + out: [2, 1, 0] + - name: "outer_noise" + in: + s: "***|**|***" + queries: [[0, 9], [0, 3], [6, 9], [3, 6]] + out: [2, 0, 0, 2] + - name: "query_boundaries" + in: + s: "|**|*|***|" + queries: [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]] + out: [6, 1, 1, 1, 0] + - name: "repeated_blocks" + in: + s: "|*|*|*|*|" + queries: [[0, 8], [0, 2], [2, 6], [4, 8], [1, 7]] + out: [4, 1, 2, 2, 2] + - name: "single_candle" + in: + s: "***|***" + queries: [[0, 6], [3, 3], [2, 5]] + out: [0, 0, 0] + - name: "candle_at_ends" + in: + s: "|****|" + queries: [[0, 5], [1, 4], [0, 4], [1, 5]] + out: [4, 0, 0, 0] + - name: "short_mixed" + in: + s: "*|*|*" + queries: [[0, 4], [1, 3], [0, 2], [2, 4]] + out: [1, 1, 0, 0] + - name: "long_plate_runs" + in: + s: "|*****|**|****|" + queries: [[0, 14], [1, 14], [6, 10], [7, 14]] + out: [11, 6, 2, 4] + - name: "alternating_even" + in: + s: "***" + queries: [[0, 2], [0, 0], [1, 2], [2, 2], [0, 1]] + out: [0, 0, 0, 0, 0] + - name: "plate_between_nonadjacent" + in: + s: "||***||****|" + queries: [[0, 11], [1, 10], [2, 8], [5, 11]] + out: [7, 3, 0, 4] + - name: "prefix_candle" + in: + s: "|**|*|**|" + queries: + - [0, 8] + - [0, 3] + - [1, 7] + out: [5, 2, 1] + - name: "suffix_candle" + in: + s: "**|*|***|" + queries: + - [0, 8] + - [2, 6] + - [4, 8] + out: [4, 1, 3] + - name: "nested_candle_ranges" + in: + s: "|*||**|*|" + queries: + - [0, 8] + - [1, 7] + - [2, 6] + - [3, 5] + out: [4, 2, 2, 0] + - name: "right_single_plate" + in: + s: "|**|*||" + queries: + - [0, 6] + - [1, 4] + - [3, 6] + out: [3, 0, 1] + - name: "left_single_plate" + in: + s: "|*|**|" + queries: + - [0, 5] + - [0, 2] + - [2, 5] + out: [3, 1, 2] + - name: "exact_candle_pair" + in: + s: "***|***|***" + queries: + - [3, 7] + - [3, 6] + - [4, 7] + out: [3, 0, 0] + - name: "multiple_pairs" + in: + s: "|**|*|****|" + queries: + - [0, 10] + - [0, 3] + - [3, 10] + - [4, 9] + out: [7, 2, 5, 0] + - name: "query_one_character" + in: + s: "|*|*|" + queries: + - [0, 0] + - [1, 1] + - [2, 2] + - [4, 4] + out: [0, 0, 0, 0] + - name: "all_ranges_same_pair" + in: + s: "|****|" + queries: + - [0, 5] + - [0, 4] + - [1, 5] + - [1, 4] + out: [4, 0, 0, 0] + - name: "alternating_odd" + in: + s: "*|*|*|*|*" + queries: + - [0, 8] + - [1, 7] + - [2, 6] + - [3, 5] + out: [3, 3, 1, 1] + - name: "long_outer_plates" + in: + s: "*****|**|*****" + queries: + - [0, 13] + - [4, 10] + - [5, 8] + out: [2, 2, 2] + - name: "candle_runs" + in: + s: "|||***|||**|" + queries: + - [0, 11] + - [2, 10] + - [3, 8] + - [8, 11] + out: [5, 3, 0, 2] + - name: "mixed_short_a" + in: + s: "*|**||*|" + queries: + - [0, 7] + - [1, 6] + - [2, 5] + out: [3, 2, 0] + - name: "mixed_short_b" + in: + s: "||*|***||" + queries: + - [0, 8] + - [1, 7] + - [2, 6] + - [4, 8] + out: [4, 4, 0, 0] + - name: "boundary_pair_only" + in: + s: "|*|***|*|" + queries: + - [0, 2] + - [6, 8] + - [0, 8] + - [2, 6] + out: [1, 1, 5, 3] + - name: "generated_balanced_small" + seed: 11 + in: + s: + gen: "str" + len: 100 + alphabet: "*|" + queries: [[0, 99], [1, 50], [20, 80], [3, 3], [40, 41]] + - name: "generated_balanced_medium" + seed: 12 + in: + s: + gen: "str" + len: 1000 + alphabet: "*|" + queries: [[0, 999], [1, 998], [100, 900], [250, 750], [499, 500]] + - name: "generated_large_a" + seed: 13 + in: + s: + gen: "str" + len: 100000 + alphabet: "*|" + queries: [[0, 99999], [1, 99998], [123, 98765], [50000, 99999], [0, 50000]] + - name: "generated_large_b" + seed: 14 + in: + s: + gen: "str" + len: 100000 + alphabet: "*|" + queries: [[0, 0], [99999, 99999], [1, 2], [33333, 66666], [2, 99997]] + - name: "generated_large_c" + seed: 15 + in: + s: + gen: "str" + len: 99999 + alphabet: "*|" + queries: [[0, 99998], [10, 99990], [25000, 75000], [1, 99998], [75000, 99998]] diff --git a/tests/2001-2500/2055. plates-between-candles/sol.py b/tests/2001-2500/2055. plates-between-candles/sol.py new file mode 100644 index 00000000..aa34e133 --- /dev/null +++ b/tests/2001-2500/2055. plates-between-candles/sol.py @@ -0,0 +1,37 @@ +class Solution(object): + def platesBetweenCandles(self, s, queries): + """ + :type s: str + :type queries: List[List[int]] + :rtype: List[int] + """ + n = len(s) + + prefix = [0] * (n + 1) + for i in range(n): + prefix[i + 1] = prefix[i] + (1 if s[i] == '*' else 0) + + left = [-1] * n + prev = -1 + for i in range(n): + if s[i] == '|': + prev = i + left[i] = prev + + right = [-1] * n + next_candle = -1 + for i in range(n - 1, -1, -1): + if s[i] == '|': + next_candle = i + right[i] = next_candle + + result = [] + for l, r in queries: + l_candle = right[l] + r_candle = left[r] + if l_candle != -1 and r_candle != -1 and l_candle < r_candle: + result.append(prefix[r_candle + 1] - prefix[l_candle]) + else: + result.append(0) + + return result \ No newline at end of file diff --git a/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/manifest.yaml b/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/manifest.yaml new file mode 100644 index 00000000..ae3bf691 --- /dev/null +++ b/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/manifest.yaml @@ -0,0 +1,316 @@ +entry: + id: 2056 + title: "number-of-valid-move-combinations-on-chessboard" + params: + pieces: + type: array + items: + type: string + positions: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().countCombinations({pieces}, {positions})" + rust: "Solution::count_combinations({pieces}, {positions})" + python3: "Solution().countCombinations({pieces}, {positions})" + python2: "Solution().countCombinations({pieces}, {positions})" + ruby: "count_combinations({pieces}, {positions})" + java: "new Solution().countCombinations({pieces}, {positions})" + csharp: "new Solution().CountCombinations({pieces}, {positions})" + kotlin: "Solution().countCombinations({pieces}, {positions})" + go: "countCombinations({pieces}, {positions})" + dart: "Solution().countCombinations({pieces}, {positions})" + swift: "Solution().countCombinations({pieces}, {positions})" + typescript: "countCombinations({pieces}, {positions})" + +judge: + type: "exact" + +limits: + time_ms: 5000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().countCombinations(pieces, positions, {result})" + checker: | + class Checker: + def countCombinations(self, pieces, positions, result): + return isinstance(result, int) and result >= 0 + +seed: 2056 + +tests: + - name: "example_rook_corner" + in: + pieces: ["rook"] + positions: + - [1, 1] + out: 15 + - name: "example_queen_corner" + in: + pieces: ["queen"] + positions: + - [1, 1] + out: 22 + - name: "example_bishop_center" + in: + pieces: ["bishop"] + positions: + - [4, 3] + out: 12 + - name: "rook_opposite_corner" + in: + pieces: ["rook"] + positions: + - [8, 8] + out: 15 + - name: "queen_opposite_corner" + in: + pieces: ["queen"] + positions: + - [8, 8] + out: 22 + - name: "bishop_light_corner" + in: + pieces: ["bishop"] + positions: + - [1, 1] + out: 8 + - name: "rook_center" + in: + pieces: ["rook"] + positions: + - [4, 4] + out: 15 + - name: "queen_center" + in: + pieces: ["queen"] + positions: + - [4, 4] + out: 28 + - name: "bishop_center_even" + in: + pieces: ["bishop"] + positions: + - [4, 4] + out: 14 + - name: "adjacent_rooks" + in: + pieces: ["rook", "rook"] + positions: + - [1, 1] + - [1, 2] + out: 196 + - name: "rooks_diagonal_corners" + in: + pieces: ["rook", "rook"] + positions: + - [1, 1] + - [8, 8] + out: 223 + - name: "rooks_same_row_edge" + in: + pieces: ["rook", "rook"] + positions: + - [4, 4] + - [4, 8] + out: 189 + - name: "rook_bishop_corners" + in: + pieces: ["rook", "bishop"] + positions: + - [1, 1] + - [8, 8] + out: 119 + - name: "bishops_opposite_corners" + in: + pieces: ["bishop", "bishop"] + positions: + - [1, 1] + - [8, 8] + out: 44 + - name: "queen_rook_corners" + in: + pieces: ["queen", "rook"] + positions: + - [1, 1] + - [8, 8] + out: 327 + - name: "queen_bishop_center_corner" + in: + pieces: ["queen", "bishop"] + positions: + - [4, 4] + - [1, 1] + out: 200 + - name: "vertical_queen_rook" + in: + pieces: ["rook", "queen"] + positions: + - [2, 4] + - [6, 4] + out: 353 + - name: "bishop_rook_same_row" + in: + pieces: ["bishop", "rook"] + positions: + - [3, 3] + - [3, 7] + out: 173 + - name: "two_queens_diagonal" + in: + pieces: ["queen", "queen"] + positions: + - [1, 1] + - [8, 8] + out: 462 + - name: "three_rooks_line" + in: + pieces: ["rook", "rook", "rook"] + positions: + - [1, 1] + - [1, 3] + - [1, 5] + out: 2163 + - name: "three_bishops_diagonal" + in: + pieces: ["bishop", "bishop", "bishop"] + positions: + - [1, 1] + - [3, 3] + - [5, 5] + out: 528 + - name: "mixed_three_corners_center" + in: + pieces: ["rook", "bishop", "queen"] + positions: + - [1, 1] + - [8, 8] + - [4, 4] + out: 2681 + - name: "two_rooks_bishop_spread" + in: + pieces: ["rook", "rook", "bishop"] + positions: + - [2, 2] + - [2, 7] + - [7, 4] + out: 1960 + - name: "queen_bishop_rook_spread" + in: + pieces: ["rook", "queen", "bishop"] + positions: + - [4, 1] + - [1, 4] + - [8, 8] + out: 2267 + - name: "four_rook_corners" + in: + pieces: ["rook", "rook", "rook", "rook"] + positions: + - [1, 1] + - [1, 8] + - [8, 1] + - [8, 8] + out: 33009 + - name: "four_bishops_edges" + in: + pieces: ["bishop", "bishop", "bishop", "bishop"] + positions: + - [1, 1] + - [1, 3] + - [8, 6] + - [8, 8] + out: 1730 + - name: "queen_rook_bishop_rook_center" + in: + pieces: ["queen", "rook", "bishop", "rook"] + positions: + - [4, 4] + - [1, 8] + - [8, 1] + - [4, 8] + out: 36292 + - name: "rook_queen_bishop_rook_edges" + in: + pieces: ["rook", "queen", "bishop", "rook"] + positions: + - [1, 4] + - [4, 1] + - [8, 8] + - [8, 4] + out: 26754 + - name: "rook_top_right" + in: + pieces: ["rook"] + positions: + - [1, 8] + out: 15 + - name: "queen_right_edge" + in: + pieces: ["queen"] + positions: + - [4, 8] + out: 22 + - name: "bishop_bottom_left" + in: + pieces: ["bishop"] + positions: + - [8, 1] + out: 8 + - name: "rook_bishop_reverse_corners" + in: + pieces: ["rook", "bishop"] + positions: + - [8, 1] + - [1, 8] + out: 119 + - name: "rook_queen_opposing_edges" + in: + pieces: ["rook", "queen"] + positions: + - [8, 4] + - [1, 5] + out: 326 + - name: "bishop_queen_opposing_diagonal" + in: + pieces: ["bishop", "queen"] + positions: + - [2, 7] + - [7, 2] + out: 220 + - name: "rooks_same_file" + in: + pieces: ["rook", "rook"] + positions: + - [2, 4] + - [7, 4] + out: 205 + - name: "bishops_same_diagonal" + in: + pieces: ["bishop", "bishop"] + positions: + - [2, 2] + - [7, 7] + out: 80 + - name: "mixed_three_edge_case" + in: + pieces: ["queen", "rook", "bishop"] + positions: + - [8, 8] + - [1, 1] + - [4, 7] + out: 2999 + - name: "maximum_four_mixed" + in: + pieces: ["rook", "bishop", "queen", "rook"] + positions: + - [2, 1] + - [7, 8] + - [4, 4] + - [8, 4] + out: 40053 diff --git a/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/sol.py b/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/sol.py new file mode 100644 index 00000000..10c3a74f --- /dev/null +++ b/tests/2001-2500/2056. number-of-valid-move-combinations-on-chessboard/sol.py @@ -0,0 +1,52 @@ +class Solution(object): + def countCombinations(self, pieces, positions): + n = len(pieces) + + mp = { + "bishop": ((-1,-1),(-1,1),(1,-1),(1,1)), + "queen": ((-1,-1),(-1,0),(-1,1), + (0,-1),(0,1), + (1,-1),(1,0),(1,1)), + "rook": ((-1,0),(0,-1),(0,1),(1,0)) + } + + dirs = [[]] + for piece in pieces: + dirs = [x + [d] for x in dirs for d in mp[piece]] + + positions = tuple(tuple(x) for x in positions) + + ans = set() + + def fn(*args): + stack = [((1 << n) - 1, positions)] + while stack: + mask, pos = stack.pop() + ans.add(pos) + + m = mask + while m: + p = [] + ok = True + for i in range(n): + if m & (1 << i): + nr = pos[i][0] + args[i][0] + nc = pos[i][1] + args[i][1] + if not (1 <= nr <= 8 and 1 <= nc <= 8): + ok = False + break + p.append((nr, nc)) + else: + p.append(pos[i]) + + if ok: + cand = tuple(p) + if len(set(cand)) == len(cand): + stack.append((m, cand)) + + m = mask & (m - 1) + + for d in dirs: + fn(*d) + + return len(ans) \ No newline at end of file diff --git a/tests/2001-2500/2057. smallest-index-with-equal-value/manifest.yaml b/tests/2001-2500/2057. smallest-index-with-equal-value/manifest.yaml new file mode 100644 index 00000000..eac4f955 --- /dev/null +++ b/tests/2001-2500/2057. smallest-index-with-equal-value/manifest.yaml @@ -0,0 +1,187 @@ +entry: + id: 2057 + title: "smallest-index-with-equal-value" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().smallestEqual({nums})" + rust: "Solution::smallest_equal({nums})" + python3: "Solution().smallestEqual({nums})" + python2: "Solution().smallestEqual({nums})" + ruby: "smallest_equal({nums})" + java: "new Solution().smallestEqual({nums})" + csharp: "new Solution().SmallestEqual({nums})" + kotlin: "Solution().smallestEqual({nums})" + go: "smallestEqual({nums})" + dart: "Solution().smallestEqual({nums})" + swift: "Solution().smallestEqual({nums})" + typescript: "smallestEqual({nums})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().smallestEqual(nums, {result})" + checker: | + class Checker: + def smallestEqual(self, nums, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + expected = -1 + for i, value in enumerate(nums): + if i % 10 == value: + expected = i + break + return result == expected + +seed: 2057 + +tests: + - name: "ex1_all_initial_matches" + in: + nums: [0, 1, 2] + out: 0 + - name: "ex2_first_match_index_two" + in: + nums: [4, 3, 2, 1] + out: 2 + - name: "ex3_no_match" + in: + nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] + out: -1 + - name: "single_zero" + in: + nums: [0] + out: 0 + - name: "single_nonzero" + in: + nums: [9] + out: -1 + - name: "match_at_one" + in: + nums: [9, 1] + out: 1 + - name: "match_at_two" + in: + nums: [8, 8, 2] + out: 2 + - name: "match_at_three" + in: + nums: [9, 8, 7, 3] + out: 3 + - name: "match_at_four" + in: + nums: [9, 8, 7, 6, 4] + out: 4 + - name: "match_at_five" + in: + nums: [9, 8, 7, 6, 5, 5] + out: 5 + - name: "match_at_six" + in: + nums: [9, 8, 7, 6, 5, 4, 6] + out: 6 + - name: "match_at_seven" + in: + nums: [9, 8, 7, 6, 5, 4, 3, 7] + out: 7 + - name: "match_at_eight" + in: + nums: [9, 8, 7, 6, 5, 4, 3, 2, 8] + out: 8 + - name: "match_at_nine" + in: + nums: [9, 8, 7, 6, 5, 4, 3, 2, 1, 9] + out: 9 + - name: "match_at_ten_zero" + in: + nums: [9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 0] + out: 10 + - name: "match_at_eleven_one" + in: + nums: [9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 1] + out: 11 + - name: "first_zero_beats_later" + in: + nums: [0, 9, 9, 3, 9, 9, 9, 7] + out: 0 + - name: "first_match_beats_index_zero" + in: + nums: [4, 1, 2, 3, 4, 5] + out: 1 + - name: "repeated_matching_values" + in: + nums: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 1 + - name: "all_nines_no_match_short" + in: + nums: [9, 9, 9, 9, 9, 9, 9, 9, 9] + out: -1 + - name: "all_zeros_match_at_zero" + in: + nums: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + out: 0 + - name: "all_fours_match_at_four" + in: + nums: [4, 4, 4, 4, 4, 4, 4] + out: 4 + - name: "zero_at_ten" + in: + nums: [9, 8, 9, 9, 9, 9, 9, 9, 9, 8, 0] + out: 10 + - name: "zero_at_twenty" + in: + nums: [9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 0] + out: 20 + - name: "late_index_twenty_one" + in: + nums: [9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 1] + out: 21 + - name: "late_index_twenty_nine" + in: + nums: [8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9] + out: 29 + - name: "large_first_match" + in: + nums: [0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9] + out: 0 + - name: "max_length_no_match" + in: + nums: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 1 + - name: "wraparound_residue_zero" + in: + nums: [7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 0, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 7] + out: 10 + - name: "wraparound_residue_one" + in: + nums: [8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 1, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8] + out: 11 + - name: "early_match_hidden_by_noise" + in: + nums: [9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9, 9, 9, 3] + out: 4 + - name: "maximum_values_with_match" + in: + nums: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] + out: 9 + - name: "alternating_values_match_one" + in: + nums: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 1 + - name: "alternating_values_match_two" + in: + nums: [8, 8, 2, 8, 2, 8, 2] + out: 2 + - name: "only_match_at_final_position" + in: + nums: [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 9] + out: 29 diff --git a/tests/2001-2500/2057. smallest-index-with-equal-value/sol.py b/tests/2001-2500/2057. smallest-index-with-equal-value/sol.py new file mode 100644 index 00000000..919602a3 --- /dev/null +++ b/tests/2001-2500/2057. smallest-index-with-equal-value/sol.py @@ -0,0 +1,8 @@ +class Solution(object): + def smallestEqual(self, nums): + r=-1 + for i in range(len(nums)): + if i%10==nums[i] : + r=i + break + return r \ No newline at end of file diff --git a/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/manifest.yaml b/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/manifest.yaml new file mode 100644 index 00000000..60c512c4 --- /dev/null +++ b/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/manifest.yaml @@ -0,0 +1,233 @@ +entry: + id: 2058 + title: "find-the-minimum-and-maximum-number-of-nodes-between-critical-points" + params: + head: + type: list_node + call: + cpp: "listNodeToArray(Solution().nodesBetweenCriticalPoints({head}))" + rust: "ListNode::list_node_to_array(Solution::nodes_between_critical_points({head}))" + python3: "Solution().nodesBetweenCriticalPoints({head})" + python2: "Solution().nodesBetweenCriticalPoints({head})" + ruby: "nodes_between_critical_points({head})" + java: "new Solution().nodesBetweenCriticalPoints({head})" + csharp: "new Solution().NodesBetweenCriticalPoints({head})" + kotlin: "Solution().nodesBetweenCriticalPoints({head})" + go: "nodesBetweenCriticalPoints({head})" + dart: "Solution().nodesBetweenCriticalPoints({head})" + swift: "Solution().nodesBetweenCriticalPoints({head})" + typescript: "nodesBetweenCriticalPoints({head})" +judge: + type: exact +limits: + time_ms: 500 + memory_mb: 256 +oracle: + python3: + call: "Checker().check(head, {result})" + checker: | + class Checker: + def check(self, head, result): + if not isinstance(result, list) or len(result) != 2: + return False + if isinstance(head, list): + values = head + else: + values = [] + node = head + while node is not None: + values.append(node.val) + node = node.next + points = [] + for i in range(1, len(values) - 1): + if (values[i] > values[i - 1] and values[i] > values[i + 1]) or (values[i] < values[i - 1] and values[i] < values[i + 1]): + points.append(i) + if len(points) < 2: + return result == [-1, -1] + distances = [points[i] - points[i - 1] for i in range(1, len(points))] + return result == [min(distances), points[-1] - points[0]] +seed: 2058 +tests: + - name: example_one_two_nodes + in: + head: [3, 1] + out: [-1, -1] + - name: example_two + in: + head: [5, 3, 1, 2, 5, 1, 2] + out: [1, 3] + - name: example_three + in: + head: [1, 3, 2, 2, 3, 2, 2, 2, 7] + out: [3, 3] + - name: two_nodes_increasing + in: + head: [1, 100000] + out: [-1, -1] + - name: three_nodes_peak + in: + head: [1, 100000, 1] + out: [-1, -1] + - name: three_nodes_valley + in: + head: [100000, 1, 100000] + out: [-1, -1] + - name: three_nodes_plateau + in: + head: [7, 7, 7] + out: [-1, -1] + - name: monotone_increasing + in: + head: [1, 2, 3, 4, 5, 6] + out: [-1, -1] + - name: monotone_decreasing + in: + head: [6, 5, 4, 3, 2, 1] + out: [-1, -1] + - name: all_equal + in: + head: [42, 42, 42, 42, 42] + out: [-1, -1] + - name: endpoint_extrema_ignored + in: + head: [100, 1, 2, 3, 100] + out: [-1, -1] + - name: two_peaks + in: + head: [1, 5, 1, 2, 4, 2] + out: [1, 3] + - name: two_valleys + in: + head: [5, 1, 4, 3, 6] + out: [1, 2] + - name: adjacent_peak_valley + in: + head: [1, 5, 1] + out: [-1, -1] + - name: alternating_four_critical + in: + head: [1, 5, 1, 5, 1, 5, 1] + out: [1, 4] + - name: alternating_start_down + in: + head: [5, 1, 5, 1, 5, 1, 5] + out: [1, 4] + - name: criticals_separated_by_plateau + in: + head: [1, 5, 3, 3, 3, 1, 4] + out: [4, 4] + - name: equal_neighbors_not_critical + in: + head: [1, 3, 3, 1, 2] + out: [-1, -1] + - name: repeated_extreme_values + in: + head: [2, 9, 1, 9, 2, 9, 1] + out: [1, 4] + - name: minimum_values + in: + head: [100000, 1, 100000, 2, 99999] + out: [1, 2] + - name: maximum_values + in: + head: [1, 100000, 2, 99999, 1] + out: [1, 2] + - name: criticals_at_indices_one_and_last_inner + in: + head: [5, 1, 5, 4, 3, 6] + out: [1, 3] + - name: close_then_far + in: + head: [1, 5, 1, 4, 1, 3, 1] + out: [1, 4] + - name: far_then_close + in: + head: [1, 5, 4, 3, 2, 1, 2, 1] + out: [1, 5] + - name: only_one_peak_with_noise + in: + head: [1, 2, 4, 3, 3, 2, 1] + out: [-1, -1] + - name: only_one_valley_with_noise + in: + head: [7, 6, 5, 6, 6, 7] + out: [-1, -1] + - name: six_critical_points + in: + head: [1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1] + out: [1, 8] + - name: long_gap_between_critical_points + in: + head: [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8] + out: [8, 8] + - name: values_with_small_plateaus + in: + head: [1, 2, 2, 1, 1, 3, 2, 2, 4] + out: [-1, -1] + - name: alternating_with_duplicate_runs + in: + head: [5, 1, 1, 5, 5, 1, 1, 5] + out: [-1, -1] + - name: four_nodes_peak_valley + in: + head: [2, 8, 1, 7] + out: [1, 1] + - name: descending_then_peak + in: + head: [9, 8, 7, 1, 2, 1] + out: [1, 1] + - name: generated_small_random + seed: 2101 + in: + head: + gen: array + len: 25 + of: + gen: int + min: 1 + max: 100000 + elemType: int + - name: generated_medium_random + seed: 2102 + in: + head: + gen: array + len: 1000 + of: + gen: int + min: 1 + max: 100000 + elemType: int + - name: generated_duplicate_heavy + seed: 2103 + in: + head: + gen: array + len: 5000 + of: + gen: int + min: 1 + max: 4 + elemType: int + - name: generated_near_maximum + seed: 2104 + in: + head: + gen: array + len: 99999 + of: + gen: int + min: 1 + max: 100000 + elemType: int + - name: generated_near_maximum_small_range + seed: 2105 + in: + head: + gen: array + len: 100000 + of: + gen: int + min: 1 + max: 3 + elemType: int diff --git a/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/sol.py b/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/sol.py new file mode 100644 index 00000000..397b520d --- /dev/null +++ b/tests/2001-2500/2058. find-the-minimum-and-maximum-number-of-nodes-between-critical-points/sol.py @@ -0,0 +1,28 @@ +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + +class Solution: + def nodesBetweenCriticalPoints(self, head): + if not head or not head.next or not head.next.next: + return [-1, -1] + prev, curr, ahead = head, head.next, head.next.next + counter = 2 + minDis = float('inf') + firstCritical = -1 + lastCritical = -1 + while ahead: + if (curr.val > prev.val and curr.val > ahead.val) or \ + (curr.val < prev.val and curr.val < ahead.val): + if firstCritical == -1: + firstCritical = counter + lastCritical = counter + else: + minDis = min(minDis, counter - lastCritical) + lastCritical = counter + counter += 1 + prev, curr, ahead = curr, ahead, ahead.next + if minDis == float('inf'): + return [-1, -1] + return [minDis, lastCritical - firstCritical] \ No newline at end of file diff --git a/tests/2001-2500/2059. minimum-operations-to-convert-number/manifest.yaml b/tests/2001-2500/2059. minimum-operations-to-convert-number/manifest.yaml new file mode 100644 index 00000000..7e102a01 --- /dev/null +++ b/tests/2001-2500/2059. minimum-operations-to-convert-number/manifest.yaml @@ -0,0 +1,345 @@ +entry: + id: 2059 + title: "minimum-operations-to-convert-number" + params: + nums: + type: array + items: + type: int + start: + type: int + goal: + type: int + call: + cpp: "Solution().minimumOperations({nums}, {start}, {goal})" + rust: "Solution::minimum_operations({nums}, {start}, {goal})" + python3: "Solution().minimumOperations({nums}, {start}, {goal})" + python2: "Solution().minimumOperations({nums}, {start}, {goal})" + ruby: "minimum_operations({nums}, {start}, {goal})" + java: "new Solution().minimumOperations({nums}, {start}, {goal})" + csharp: "new Solution().MinimumOperations({nums}, {start}, {goal})" + kotlin: "Solution().minimumOperations({nums}, {start}, {goal})" + go: "minimumOperations({nums}, {start}, {goal})" + dart: "Solution().minimumOperations({nums}, {start}, {goal})" + swift: "Solution().minimumOperations({nums}, {start}, {goal})" + typescript: "minimumOperations({nums}, {start}, {goal})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumOperations(nums, start, goal, {result})" + checker: | + from collections import deque + class Checker: + def minimumOperations(self, nums, start, goal, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + seen = {start} + q = deque([(start, 0)]) + answer = -1 + while q: + x, d = q.popleft() + if x == goal: + answer = d + break + if not (0 <= x <= 1000): + continue + for n in nums: + for y in (x + n, x - n, x ^ n): + if y == goal: + answer = d + 1 + q.clear() + break + if 0 <= y <= 1000 and y not in seen: + seen.add(y) + q.append((y, d + 1)) + if answer != -1: + break + if answer != -1: + break + return result == answer + +seed: 2059 + +tests: + - name: "example_add_sub" + in: + nums: [2, 4, 12] + start: 2 + goal: 12 + out: 2 + - name: "example_negative_goal" + in: + nums: [3, 5, 7] + start: 0 + goal: -4 + out: 2 + - name: "example_unreachable" + in: + nums: [2, 8, 16] + start: 0 + goal: 1 + out: -1 + - name: "direct_add" + in: + nums: [5] + start: 0 + goal: 5 + out: 1 + - name: "direct_subtract_to_negative" + in: + nums: [9] + start: 4 + goal: -5 + out: 1 + - name: "direct_xor_zero" + in: + nums: [37] + start: 37 + goal: 0 + out: 1 + - name: "direct_xor_boundary" + in: + nums: [1023] + start: 0 + goal: 1023 + out: 1 + - name: "start_zero_to_one" + in: + nums: [1] + start: 0 + goal: 1 + out: 1 + - name: "start_max_to_zero" + in: + nums: [1000] + start: 1000 + goal: 0 + out: 1 + - name: "single_increment_two" + in: + nums: [1] + start: 0 + goal: 2 + out: 2 + - name: "single_increment_ten" + in: + nums: [1] + start: 10 + goal: 20 + out: 10 + - name: "single_decrement_to_zero" + in: + nums: [1] + start: 10 + goal: 0 + out: 10 + - name: "single_xor_chain" + in: + nums: [3] + start: 0 + goal: 6 + out: 2 + - name: "two_step_small" + in: + nums: [2, 5] + start: 0 + goal: 7 + out: 2 + - name: "two_step_cancel" + in: + nums: [4, 9] + start: 20 + goal: 7 + out: 2 + - name: "xor_then_add" + in: + nums: [6, 10] + start: 5 + goal: 19 + out: 3 + - name: "negative_num_direct" + in: + nums: [-3] + start: 10 + goal: 7 + out: 1 + - name: "negative_num_outside" + in: + nums: [-100] + start: 0 + goal: -100 + out: 1 + - name: "large_direct_goal" + in: + nums: [1000000000] + start: 0 + goal: 1000000000 + out: 1 + - name: "large_negative_direct" + in: + nums: [-1000000000] + start: 1000 + goal: -999999000 + out: 1 + - name: "large_num_unreachable" + in: + nums: [1000000000] + start: 1 + goal: 2 + out: -1 + - name: "odd_parity_unreachable" + in: + nums: [2, 4, 8] + start: 0 + goal: 3 + out: -1 + - name: "zero_like_xor_unreachable" + in: + nums: [10, 20] + start: 5 + goal: 6 + out: -1 + - name: "boundary_inside_to_outside" + in: + nums: [1] + start: 1000 + goal: 1001 + out: 1 + - name: "boundary_subtract" + in: + nums: [1] + start: 0 + goal: -1 + out: 1 + - name: "many_options_shortest" + in: + nums: [1, 7, 11, 20] + start: 100 + goal: 120 + out: 1 + - name: "distinct_large_values" + in: + nums: [999, 998, 997] + start: 1 + goal: 1000 + out: 1 + - name: "xor_high_bits" + in: + nums: [512] + start: 511 + goal: 1023 + out: 1 + - name: "negative_goal_two_steps" + in: + nums: [1, 100] + start: 0 + goal: -99 + out: 2 + - name: "zero_start_large_path" + in: + nums: [10, 20, 30] + start: 0 + goal: 60 + out: 2 + - name: "gen_small_distinct" + seed: 301 + in: + nums: + gen: "array" + len: 8 + of: + gen: "int" + min: -20 + max: 20 + distinct: true + start: + gen: "int" + min: 0 + max: 1000 + goal: + gen: "int" + min: -1000 + max: 1000 + - name: "gen_medium_distinct" + seed: 302 + in: + nums: + gen: "array" + len: 30 + of: + gen: "int" + min: -1000 + max: 1000 + distinct: true + start: + gen: "int" + min: 0 + max: 1000 + goal: + gen: "int" + min: -1000000000 + max: 1000000000 + - name: "gen_dense_boundary_values" + seed: 303 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: -1000000 + max: 1000000 + distinct: true + start: + gen: "int" + min: 0 + max: 1000 + goal: + gen: "int" + min: -1000000000 + max: 1000000000 + - name: "gen_large_1000_a" + seed: 304 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: -1000000000 + max: 1000000000 + distinct: true + start: + gen: "int" + min: 0 + max: 1000 + goal: + gen: "int" + min: -1000000000 + max: 1000000000 + - name: "gen_large_1000_b" + seed: 305 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: -1000000000 + max: 1000000000 + distinct: true + start: + gen: "int" + min: 0 + max: 1000 + goal: + gen: "int" + min: -1000000000 + max: 1000000000 diff --git a/tests/2001-2500/2059. minimum-operations-to-convert-number/sol.py b/tests/2001-2500/2059. minimum-operations-to-convert-number/sol.py new file mode 100644 index 00000000..6e363434 --- /dev/null +++ b/tests/2001-2500/2059. minimum-operations-to-convert-number/sol.py @@ -0,0 +1,31 @@ +class Solution(object): + def minimumOperations(self, nums, start, goal): + """ + :type nums: List[int] + :type start: int + :type goal: int + :rtype: int + """ + visited = [False] * 1001 + queue = deque() + queue.append((start, 0)) + + while queue: + x, steps = queue.popleft() + + if x == goal: + return steps + + if 0 <= x <= 1000 and visited[x]: + continue + if 0 <= x <= 1000: + visited[x] = True + + for num in nums: + for new_x in (x + num, x - num, x ^ num): + if 0 <= new_x <= 1000 and not visited[new_x]: + queue.append((new_x, steps + 1)) + elif new_x == goal: + return steps + 1 + + return -1 \ No newline at end of file diff --git a/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/manifest.yaml b/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/manifest.yaml new file mode 100644 index 00000000..6acc064d --- /dev/null +++ b/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/manifest.yaml @@ -0,0 +1,266 @@ +entry: + id: 2060 + title: "check-if-an-original-string-exists-given-two-encoded-strings" + params: + s1: + type: string + s2: + type: string + call: + cpp: "Solution().possiblyEquals({s1}, {s2})" + rust: "Solution::possibly_equals({s1}, {s2})" + python3: "Solution().possiblyEquals({s1}, {s2})" + python2: "Solution().possiblyEquals({s1}, {s2})" + ruby: "possibly_equals({s1}, {s2})" + java: "new Solution().possiblyEquals({s1}, {s2})" + csharp: "new Solution().PossiblyEquals({s1}, {s2})" + kotlin: "Solution().possiblyEquals({s1}, {s2})" + go: "possiblyEquals({s1}, {s2})" + dart: "Solution().possiblyEquals({s1}, {s2})" + swift: "Solution().possiblyEquals({s1}, {s2})" + typescript: "possiblyEquals({s1}, {s2})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().possiblyEquals(s1, s2, {result})" + checker: | + class Checker: + def possiblyEquals(self, s1, s2, result): + if not isinstance(result, bool): + return False + seen = set() + stack = [(0, 0, 0)] + while stack: + i, j, delta = stack.pop() + state = (i, j, delta) + if state in seen: + continue + seen.add(state) + if i == len(s1) and j == len(s2) and delta == 0: + return result is True + if i < len(s1) and s1[i].isdigit(): + value = 0 + k = i + while k < len(s1) and s1[k].isdigit(): + value = value * 10 + int(s1[k]) + k += 1 + stack.append((k, j, delta - value)) + continue + if j < len(s2) and s2[j].isdigit(): + value = 0 + k = j + while k < len(s2) and s2[k].isdigit(): + value = value * 10 + int(s2[k]) + k += 1 + stack.append((i, k, delta + value)) + continue + if delta > 0 and i < len(s1) and not s1[i].isdigit(): + stack.append((i + 1, j, delta - 1)) + continue + if delta < 0 and j < len(s2) and not s2[j].isdigit(): + stack.append((i, j + 1, delta + 1)) + continue + if delta == 0 and i < len(s1) and j < len(s2) and s1[i] == s2[j]: + stack.append((i + 1, j + 1, 0)) + return result is False + +seed: 2060 + +tests: + - name: "example_internationalization" + in: + s1: "internationalization" + s2: "i18n" + out: true + - name: "example_leetcode" + in: + s1: "l123e" + s2: "44" + out: true + - name: "example_conflicting_letters" + in: + s1: "a5b" + s2: "c5b" + out: false + - name: "same_single_letter" + in: + s1: "a" + s2: "a" + out: true + - name: "different_single_letters" + in: + s1: "a" + s2: "b" + out: false + - name: "same_single_digit" + in: + s1: "1" + s2: "1" + out: true + - name: "different_single_digits" + in: + s1: "1" + s2: "2" + out: false + - name: "same_boundary_digit" + in: + s1: "9" + s2: "9" + out: true + - name: "nine_vs_ten" + in: + s1: "9" + s2: "10" + out: false + - name: "same_two_digit_count" + in: + s1: "10" + s2: "10" + out: true + - name: "same_two_digit_max" + in: + s1: "99" + s2: "99" + out: true + - name: "same_three_digit_max" + in: + s1: "999" + s2: "999" + out: true + - name: "literal_segment_match" + in: + s1: "a1b" + s2: "a1b" + out: true + - name: "literal_segment_mismatch" + in: + s1: "a1b" + s2: "a2b" + out: false + - name: "digit_letter_reordering" + in: + s1: "a1b" + s2: "ab1" + out: true + - name: "letters_equal_one_digit" + in: + s1: "ab" + s2: "2" + out: true + - name: "letters_equal_split_digits" + in: + s1: "ab" + s2: "11" + out: true + - name: "three_letters_equal_count" + in: + s1: "abc" + s2: "3" + out: true + - name: "prefix_letter_and_count" + in: + s1: "abc" + s2: "2c" + out: true + - name: "middle_letter_between_counts" + in: + s1: "abc" + s2: "1b1" + out: true + - name: "unmatched_prefix_count" + in: + s1: "a2c" + s2: "3" + out: false + - name: "conflicting_letter_after_count" + in: + s1: "a2c" + s2: "b3" + out: false + - name: "count_cannot_cover_suffix" + in: + s1: "a12z" + s2: "12" + out: false + - name: "count_with_wrong_suffix_letter" + in: + s1: "a12z" + s2: "3z" + out: false + - name: "leading_count_with_matching_letter" + in: + s1: "12a" + s2: "3a" + out: true + - name: "three_digit_string_vs_count" + in: + s1: "123" + s2: "6" + out: true + - name: "three_digit_string_vs_split_count" + in: + s1: "123" + s2: "33" + out: true + - name: "count_letter_count_mismatch" + in: + s1: "1a2" + s2: "3" + out: false + - name: "count_letter_count_match" + in: + s1: "1a2" + s2: "2a1" + out: true + - name: "letter_plus_nine_vs_ten" + in: + s1: "a9" + s2: "10" + out: true + - name: "letter_conflict_plus_count" + in: + s1: "a9" + s2: "b10" + out: false + - name: "ambiguous_large_count_mismatch" + in: + s1: "x123y" + s2: "124" + out: false + - name: "letters_and_count_alignment" + in: + s1: "abc123def" + s2: "3abc123" + out: true + - name: "interleaved_count_mismatch" + in: + s1: "a1b2c3d" + s2: "6" + out: false + - name: "repeated_count_letter_mismatch" + in: + s1: "1a1a1a" + s2: "3a3" + out: false + - name: "maximum_length_all_digits" + in: + s1: "99999999999999999999999999999999999999" + s2: "99999999999999999999999999999999999999" + out: true + - name: "long_repeated_blocks" + in: + s1: "abc123abc123abc123abc123abc123abc123" + s2: "36" + out: false + - name: "long_interleaved_mismatch" + in: + s1: "a1b2c3d4e5f6g7h8i9j" + s2: "19" + out: false diff --git a/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/sol.py b/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/sol.py new file mode 100644 index 00000000..e9c55ff0 --- /dev/null +++ b/tests/2001-2500/2060. check-if-an-original-string-exists-given-two-encoded-strings/sol.py @@ -0,0 +1,86 @@ +class Solution(object): + def possiblyEquals(self, s1, s2): + """ + :type s1: str + :type s2: str + :rtype: bool + """ + mem = {} + # p1 is pointer to s1 for next character to process + # and p2 is pointer to s2 for next character to process + # diff is the number of characters to match in s1 - + # number of characters to match in s2 + # if s1 has digits x, then s2 has x more characters to match, + # decrement diff by x + # if s2 has digits x, then s1 has x more characters to match, + # increment diff by x + # diff is positive if s1 has more unmatched characters + # diff is negative if s2 has more unmatched characters + # if diff is 0, s1 and s2 are matched so far + def dfs(p1, p2, diff): + if (p1, p2, diff) in mem: + return mem[(p1,p2,diff)] + #print("compare s1:"+ s1[p1:] + " s2:" + s2[p2:] + " diff:" + str(diff)) + # base cases + if p1 == len(s1) and diff > 0: + mem[(p1, p2, diff)] = False + return False + if p2 == len(s2) and diff < 0: + mem[(p1, p2, diff)] = False + return False + if p1 > len(s1) or p2 > len(s2): + #assert("index out of range") + mem[(p1, p2, diff)] = False + return False + + # non digit case: diff > 0 + if diff > 0: + # move p1 to catch up and reduce diff + if p1 < len(s1): + if not s1[p1].isdigit(): + return dfs(p1+1, p2, diff-1) + + # non digit case: diff < 0 + if diff < 0: + # move p2 to catch up and increase diff + if p2 < len(s2): + if not s2[p2].isdigit(): + return dfs(p1, p2+1, diff+1) + + # digit case: s1 + if p1 < len(s1) and s1[p1].isdigit(): + n = 0 + t = p1 + while t < len(s1) and s1[t].isdigit(): + n = n*10 + int(s1[t]) + t += 1 + if dfs(t, p2, diff-n): + return True + mem[(p1, p2, diff)] = False + return False + + # digit case: s2 + if p2 < len(s2) and s2[p2].isdigit(): + n = 0 + t = p2 + while t < len(s2) and s2[t].isdigit(): + n = n*10 + int(s2[t]) + t += 1 + if dfs(p1, t, diff+n): + return True + mem[(p1, p2, diff)] = False + return False + + # non digit case: both p1 and p2 are letters + if p1 < len(s1) and p2 < len(s2) and s1[p1] != s2[p2]: + mem[(p1, p2, diff)] = False + return False + if dfs(p1+1, p2+1, diff): + return True + + # non digit base case + result = ( diff == 0 and p1 == len(s1) and p2 == len(s2)) + mem[(p1, p2, diff)] = result + return result + + return dfs(0,0,0) \ No newline at end of file diff --git a/tests/2001-2500/2062. count-vowel-substrings-of-a-string/manifest.yaml b/tests/2001-2500/2062. count-vowel-substrings-of-a-string/manifest.yaml new file mode 100644 index 00000000..557b35dd --- /dev/null +++ b/tests/2001-2500/2062. count-vowel-substrings-of-a-string/manifest.yaml @@ -0,0 +1,221 @@ +entry: + id: 2062 + title: "count-vowel-substrings-of-a-string" + params: + word: + type: string + call: + cpp: "Solution().countVowelSubstrings({word})" + rust: "Solution::count_vowel_substrings({word})" + python3: "Solution().countVowelSubstrings({word})" + python2: "Solution().countVowelSubstrings({word})" + ruby: "count_vowel_substrings({word})" + java: "new Solution().countVowelSubstrings({word})" + csharp: "new Solution().CountVowelSubstrings({word})" + kotlin: "Solution().countVowelSubstrings({word})" + go: "countVowelSubstrings({word})" + dart: "Solution().countVowelSubstrings({word})" + swift: "Solution().countVowelSubstrings({word})" + typescript: "countVowelSubstrings({word})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countVowelSubstrings(word, {result})" + checker: | + class Checker: + def countVowelSubstrings(self, word, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + vowels = set("aeiou") + expected = 0 + for start in range(len(word)): + seen = set() + for end in range(start, len(word)): + if word[end] not in vowels: + break + seen.add(word[end]) + if len(seen) == 5: + expected += 1 + return result == expected + +seed: 2062 + +tests: + - name: "example_1" + in: + word: "aeiouu" + out: 2 + - name: "example_2_no_complete_set" + in: + word: "unicornarihan" + out: 0 + - name: "example_3_overlapping" + in: + word: "cuaieuouac" + out: 7 + - name: "single_consonant" + in: + word: "b" + out: 0 + - name: "single_vowel" + in: + word: "a" + out: 0 + - name: "all_vowels_once" + in: + word: "aeiou" + out: 1 + - name: "all_vowels_reverse" + in: + word: "uoiea" + out: 1 + - name: "missing_a" + in: + word: "eiou" + out: 0 + - name: "missing_u" + in: + word: "aeio" + out: 0 + - name: "consonants_split_runs" + in: + word: "zaeioub" + out: 1 + - name: "leading_and_trailing_consonants" + in: + word: "xaeiouf" + out: 1 + - name: "two_identical_blocks" + in: + word: "aeioubcaeiou" + out: 2 + - name: "two_blocks_without_separator" + in: + word: "aeiouaeiou" + out: 21 + - name: "extra_a" + in: + word: "aaeiou" + out: 2 + - name: "extra_u" + in: + word: "aeiouuu" + out: 3 + - name: "extra_each_vowel" + in: + word: "aaeeiioouu" + out: 4 + - name: "permuted_with_duplicates" + in: + word: "uuaeiiooa" + out: 6 + - name: "complete_set_at_end" + in: + word: "aaaaaeiou" + out: 5 + - name: "complete_set_at_start" + in: + word: "aeiouxxxxx" + out: 1 + - name: "vowel_run_missing_one_then_complete" + in: + word: "aeioaaeiou" + out: 6 + - name: "alternating_consonants" + in: + word: "abecidofu" + out: 0 + - name: "long_consonant_run" + in: + word: "bcdfghjklmnpqrstvwxyz" + out: 0 + - name: "maximum_length_no_vowels" + in: + word: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + out: 0 + - name: "maximum_length_all_a" + in: + word: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + out: 0 + - name: "long_run_one_complete_set" + in: + word: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeiou" + out: 50 + - name: "long_run_many_completions" + in: + word: "aeiouaeiouaeiouaeiouaeiou" + out: 231 + - name: "separator_between_every_vowel" + in: + word: "axbexicoxu" + out: 0 + - name: "repeated_complete_runs" + in: + word: "aeiouuaeiouo" + out: 31 + - name: "suffix_extensions" + in: + word: "cuaieuououac" + out: 11 + - name: "vowels_with_internal_break" + in: + word: "aeiobuaeou" + out: 0 + - name: "all_vowels_then_break_then_all" + in: + word: "aeiouxaeiou" + out: 2 + - name: "generated_short_lowercase" + seed: 101 + in: + word: + gen: "str" + len: + gen: "int" + min: 1 + max: 20 + alphabet: "aeioubc" + - name: "generated_medium_vowel_heavy" + seed: 202 + in: + word: + gen: "str" + len: + gen: "int" + min: 21 + max: 60 + alphabet: "aeioux" + - name: "generated_medium_consonant_heavy" + seed: 303 + in: + word: + gen: "str" + len: + gen: "int" + min: 40 + max: 80 + alphabet: "aeioubcdfgh" + - name: "generated_near_maximum" + seed: 404 + in: + word: + gen: "str" + len: + gen: "int" + min: 90 + max: 100 + alphabet: "aeiumnrs" + - name: "generated_maximum_lowercase" + seed: 505 + in: + word: + gen: "str" + len: 100 + alphabet: "aeiubcdfghjklmnpqrstvwxyz" diff --git a/tests/2001-2500/2062. count-vowel-substrings-of-a-string/sol.py b/tests/2001-2500/2062. count-vowel-substrings-of-a-string/sol.py new file mode 100644 index 00000000..178a8fc4 --- /dev/null +++ b/tests/2001-2500/2062. count-vowel-substrings-of-a-string/sol.py @@ -0,0 +1,33 @@ +from collections import defaultdict + +class Solution: + def countVowelSubstrings(self, word): + vowels_map = {'a': True, 'e': True, 'i': True, 'o': True, 'u': True} + + len_word = len(word) + + left_index = 0 + right_index = 0 + ret_val = 0 + char_to_freq_map = defaultdict(int) + + i = 0 + while (i < len_word): + c = word[i] + if c in vowels_map.keys(): + char_to_freq_map[c] += 1 + + while set(char_to_freq_map.keys()) == set(vowels_map.keys()): + c = word[right_index] + char_to_freq_map[c] -= 1 + if (char_to_freq_map[c] <= 0): + char_to_freq_map.pop(c) + right_index += 1 + ret_val += (right_index - left_index) + else: + char_to_freq_map.clear() + left_index = i + 1 + right_index = i + 1 + i += 1 + + return ret_val \ No newline at end of file diff --git a/tests/2001-2500/2063. vowels-of-all-substrings/manifest.yaml b/tests/2001-2500/2063. vowels-of-all-substrings/manifest.yaml new file mode 100644 index 00000000..f9ee317b --- /dev/null +++ b/tests/2001-2500/2063. vowels-of-all-substrings/manifest.yaml @@ -0,0 +1,196 @@ +entry: + id: 2063 + title: "vowels-of-all-substrings" + params: + word: + type: string + call: + cpp: "Solution().countVowels({word})" + rust: "Solution::count_vowels({word})" + python3: "Solution().countVowels({word})" + python2: "Solution().countVowels({word})" + ruby: "count_vowels({word})" + java: "new Solution().countVowels({word})" + csharp: "new Solution().CountVowels({word})" + kotlin: "Solution().countVowels({word})" + go: "countVowels({word})" + dart: "Solution().countVowels({word})" + swift: "Solution().countVowels({word})" + typescript: "countVowels({word})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countVowels(word, {result})" + checker: | + class Checker: + def countVowels(self, word, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + expected = 0 + vowels = set("aeiou") + n = len(word) + for i, ch in enumerate(word): + if ch in vowels: + expected += (i + 1) * (n - i) + return result == expected + +seed: 2063 + +tests: + - name: "ex1_aba" + in: + word: "aba" + out: 6 + - name: "ex2_abc" + in: + word: "abc" + out: 3 + - name: "ex3_no_vowels" + in: + word: "ltcd" + out: 0 + - name: "single_vowel_a" + in: + word: "a" + out: 1 + - name: "single_consonant" + in: + word: "z" + out: 0 + - name: "single_vowel_u" + in: + word: "u" + out: 1 + - name: "all_vowels_once" + in: + word: "aeiou" + out: 35 + - name: "all_consonants" + in: + word: "bcdfghjklmnpqrstvwxyz" + out: 0 + - name: "vowels_at_start" + in: + word: "aei" + out: 10 + - name: "vowels_at_end" + in: + word: "xyzou" + out: 13 + - name: "alternating_short" + in: + word: "ababab" + out: 28 + - name: "alternating_long" + in: + word: "ababababab" + out: 110 + - name: "repeated_a_5" + in: + word: "aaaaa" + out: 35 + - name: "repeated_e_10" + in: + word: "eeeeeeeeee" + out: 220 + - name: "repeated_i_20" + in: + word: "iiiiiiiiiiiiiiiiiiii" + out: 1540 + - name: "repeated_o_50" + in: + word: "oooooooooooooooooooooooooooooooooooooooooooooooooo" + out: 22100 + - name: "repeated_u_100" + in: + word: "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" + out: 171700 + - name: "vowel_middle" + in: + word: "bcdaefgh" + out: 40 + - name: "mixed_clusters" + in: + word: "aeiobcdfu" + out: 79 + - name: "vowel_each_boundary" + in: + word: "aazzeexxiioouu" + out: 368 + - name: "mostly_consonants" + in: + word: "qwerty" + out: 12 + - name: "vowels_with_y" + in: + word: "whyareyou" + out: 73 + - name: "palindrome" + in: + word: "aeiui" + out: 35 + - name: "long_consonant_gap" + in: + word: "aabcdefghij" + out: 87 + - name: "vowel_then_gap_then_vowel" + in: + word: "aabcdefghijku" + out: 138 + - name: "dense_mixed" + in: + word: "thequickbrownfoxjumpsoverthelazydog" + out: 2416 + - name: "case_lowercase_only" + in: + word: "leetcode" + out: 58 + - name: "front_loaded" + in: + word: "aeiobcdfgh" + out: 80 + - name: "back_loaded" + in: + word: "bcdfghaeiou" + out: 125 + - name: "two_vowels_far" + in: + word: "aabcdefghijklmnopqrstuvwxyzu" + out: 800 + - name: "large_all_a" + in: + word: + gen: "str" + len: 100000 + alphabet: "a" + - name: "large_all_z" + in: + word: + gen: "str" + len: 100000 + alphabet: "z" + - name: "large_mixed_binary" + in: + word: + gen: "str" + len: 99999 + alphabet: "ab" + - name: "generated_short_lowercase" + in: + word: + gen: "str" + len: 37 + alphabet: "aeioubcx" + - name: "generated_medium_lowercase" + in: + word: + gen: "str" + len: 4096 + alphabet: "aeioubdgmt" diff --git a/tests/2001-2500/2063. vowels-of-all-substrings/sol.py b/tests/2001-2500/2063. vowels-of-all-substrings/sol.py new file mode 100644 index 00000000..47832f1d --- /dev/null +++ b/tests/2001-2500/2063. vowels-of-all-substrings/sol.py @@ -0,0 +1,14 @@ +class Solution: + def countVowels(self, word: str) -> int: + + vowels = set("aeiou") + n = len(word) + ans = 0 + + for i in range(n): + if word[i] in vowels: + left = i + 1 + right = n - i + ans += left * right + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/manifest.yaml b/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/manifest.yaml new file mode 100644 index 00000000..2abc3574 --- /dev/null +++ b/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/manifest.yaml @@ -0,0 +1,230 @@ +entry: + id: 2064 + title: "minimized-maximum-of-products-distributed-to-any-store" + params: + n: + type: int + quantities: + type: array + items: + type: int + call: + cpp: "Solution().minimizedMaximum({n}, {quantities})" + rust: "Solution::minimized_maximum({n}, {quantities})" + python3: "Solution().minimizedMaximum({n}, {quantities})" + python2: "Solution().minimizedMaximum({n}, {quantities})" + ruby: "minimized_maximum({n}, {quantities})" + java: "new Solution().minimizedMaximum({n}, {quantities})" + csharp: "new Solution().MinimizedMaximum({n}, {quantities})" + kotlin: "Solution().minimizedMaximum({n}, {quantities})" + go: "minimizedMaximum({n}, {quantities})" + dart: "Solution().minimizedMaximum({n}, {quantities})" + swift: "Solution().minimizedMaximum({n}, {quantities})" + typescript: "minimizedMaximum({n}, {quantities})" + +judge: + type: "exact" + +limits: + time_ms: 300 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimizedMaximum(n, quantities, {result})" + checker: | + class Checker: + def minimizedMaximum(self, n, quantities, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + if result < 1: + return False + if sum((q + result - 1) // result for q in quantities) > n: + return False + if result == 1: + return all(q == 1 for q in quantities) + return sum((q + result - 2) // (result - 1) for q in quantities) > n + +seed: 2064 + +tests: + - name: "example_one" + in: + n: 6 + quantities: [11, 6] + out: 3 + - name: "example_two" + in: + n: 7 + quantities: [15, 10, 10] + out: 5 + - name: "example_three_single_store" + in: + n: 1 + quantities: [100000] + out: 100000 + - name: "all_minimum_singletons" + in: + n: 2 + quantities: [1, 1] + out: 1 + - name: "one_store_per_type" + in: + n: 3 + quantities: [1, 1, 1] + out: 1 + - name: "extra_stores_for_small_types" + in: + n: 5 + quantities: [1, 1] + out: 1 + - name: "largest_type_with_minimum_stores" + in: + n: 2 + quantities: [100000, 1] + out: 100000 + - name: "equal_maximum_types_tight" + in: + n: 3 + quantities: [100000, 100000] + out: 100000 + - name: "equal_nine_types" + in: + n: 4 + quantities: [9, 9, 9, 9] + out: 9 + - name: "one_large_and_four_singletons" + in: + n: 5 + quantities: [10, 1, 1, 1, 1] + out: 10 + - name: "many_stores_one_type" + in: + n: 10 + quantities: [10] + out: 1 + - name: "balanced_two_types" + in: + n: 10 + quantities: [100, 100] + out: 20 + - name: "highly_unbalanced_two_types" + in: + n: 10 + quantities: [1, 100000] + out: 11112 + - name: "hundred_stores_two_large_types" + in: + n: 100 + quantities: [100000, 100000] + out: 2000 + - name: "three_equal_fives" + in: + n: 6 + quantities: [5, 5, 5] + out: 3 + - name: "three_equal_tens" + in: + n: 6 + quantities: [10, 10, 10] + out: 5 + - name: "small_tail_changes_ceiling" + in: + n: 8 + quantities: [7, 1, 1, 1] + out: 2 + - name: "large_first_type_small_tail" + in: + n: 8 + quantities: [16, 1, 1, 1] + out: 4 + - name: "five_equal_twenty" + in: + n: 10 + quantities: [20, 20, 20, 20, 20] + out: 10 + - name: "five_equal_nineteen" + in: + n: 10 + quantities: [19, 19, 19, 19, 19] + out: 10 + - name: "exactly_one_store_each" + in: + n: 5 + quantities: [2, 3, 4, 5, 6] + out: 6 + - name: "one_extra_store" + in: + n: 6 + quantities: [2, 3, 4, 5, 6] + out: 5 + - name: "ten_equal_threes" + in: + n: 10 + quantities: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3] + out: 3 + - name: "maximum_n_single_type" + in: + n: 100000 + quantities: [100000] + out: 1 + - name: "maximum_n_small_types" + in: + n: 100000 + quantities: [1, 1, 1] + out: 1 + - name: "three_maximum_types_abundant" + in: + n: 100000 + quantities: [100000, 100000, 100000] + out: 4 + - name: "two_maximum_types_near_max_n" + in: + n: 99999 + quantities: [100000, 100000] + out: 3 + - name: "two_large_and_singleton_abundant" + in: + n: 100000 + quantities: [100000, 99999, 1] + out: 3 + - name: "ascending_ten_types" + in: + n: 50 + quantities: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: 2 + - name: "eleven_equal_eleven" + in: + n: 11 + quantities: [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11] + out: 11 + - name: "hundred_with_eleven_types" + in: + n: 12 + quantities: [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 50 + - name: "descending_five_types" + in: + n: 15 + quantities: [14, 13, 12, 11, 10] + out: 5 + - name: "geometric_quantities" + in: + n: 20 + quantities: [1000, 500, 250, 125] + out: 100 + - name: "nine_equal_eights" + in: + n: 9 + quantities: [8, 8, 8, 8, 8, 8, 8, 8, 8] + out: 8 + - name: "mixed_primes" + in: + n: 12 + quantities: [23, 17, 13, 11, 7, 5] + out: 8 + - name: "large_type_with_nine_singletons" + in: + n: 100 + quantities: [100000, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 1099 diff --git a/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/sol.py b/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/sol.py new file mode 100644 index 00000000..3df0b43c --- /dev/null +++ b/tests/2001-2500/2064. minimized-maximum-of-products-distributed-to-any-store/sol.py @@ -0,0 +1,3 @@ +class Solution: + def minimizedMaximum(self, n: int, q: List[int]) -> int: + return bisect_left(range(max(q)),0,1,key=lambda x:sum(-v//x for v in q)+n) \ No newline at end of file diff --git a/tests/2001-2500/2065. maximum-path-quality-of-a-graph/manifest.yaml b/tests/2001-2500/2065. maximum-path-quality-of-a-graph/manifest.yaml new file mode 100644 index 00000000..ce9cce1a --- /dev/null +++ b/tests/2001-2500/2065. maximum-path-quality-of-a-graph/manifest.yaml @@ -0,0 +1,403 @@ +entry: + id: 2065 + title: "maximum-path-quality-of-a-graph" + params: + values: + type: array + items: + type: int + edges: + type: array + items: + type: array + items: + type: int + maxTime: + type: int + call: + cpp: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + rust: "Solution::maximal_path_quality({values}, {edges}, {maxTime})" + python3: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + python2: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + ruby: "maximal_path_quality({values}, {edges}, {maxTime})" + java: "new Solution().maximalPathQuality({values}, {edges}, {maxTime})" + csharp: "new Solution().MaximalPathQuality({values}, {edges}, {maxTime})" + kotlin: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + go: "maximalPathQuality({values}, {edges}, {maxTime})" + dart: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + swift: "Solution().maximalPathQuality({values}, {edges}, {maxTime})" + typescript: "maximalPathQuality({values}, {edges}, {maxTime})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maximalPathQuality(values, edges, maxTime, {result})" + checker: | + class Checker: + def maximalPathQuality(self, values, edges, maxTime, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + graph = [[] for _ in values] + for u, v, t in edges: + graph[u].append((v, t)) + graph[v].append((u, t)) + best = 0 + def dfs(node, remaining, score, mask): + nonlocal best + if node == 0: + best = max(best, score) + for nxt, cost in graph[node]: + if cost <= remaining: + dfs(nxt, remaining - cost, score if mask & (1 << nxt) else score + values[nxt], mask | (1 << nxt)) + dfs(0, maxTime, values[0], 1) + return result == best + +seed: 2065 + +tests: + - name: "example_1" + in: + values: [0, 32, 10, 43] + edges: + - [0, 1, 10] + - [1, 2, 15] + - [0, 3, 10] + maxTime: 49 + out: 75 + - name: "example_2" + in: + values: [5, 10, 15, 20] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [0, 3, 10] + maxTime: 30 + out: 25 + - name: "example_3" + in: + values: [1, 2, 3, 4] + edges: + - [0, 1, 10] + - [1, 2, 11] + - [2, 3, 12] + - [1, 3, 13] + maxTime: 50 + out: 7 + - name: "single_node_no_edges" + in: + values: [7] + edges: [] + maxTime: 10 + out: 7 + - name: "start_zero_value" + in: + values: [0, 9] + edges: + - [0, 1, 10] + maxTime: 10 + out: 0 + - name: "insufficient_return_time" + in: + values: [4, 100] + edges: + - [0, 1, 10] + maxTime: 19 + out: 4 + - name: "exact_round_trip" + in: + values: [4, 100] + edges: + - [0, 1, 10] + maxTime: 20 + out: 104 + - name: "disconnected_high_value" + in: + values: [3, 4, 999] + edges: + - [0, 1, 10] + maxTime: 20 + out: 7 + - name: "zero_value_leaf" + in: + values: [8, 0] + edges: + - [0, 1, 10] + maxTime: 20 + out: 8 + - name: "two_equal_branches" + in: + values: [1, 5, 7] + edges: + - [0, 1, 10] + - [0, 2, 10] + maxTime: 40 + out: 13 + - name: "branch_budget_one" + in: + values: [1, 5, 7] + edges: + - [0, 1, 10] + - [0, 2, 10] + maxTime: 20 + out: 8 + - name: "chain_all_nodes" + in: + values: [1, 2, 3, 4, 5] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + maxTime: 80 + out: 15 + - name: "chain_missing_last" + in: + values: [1, 2, 3, 4, 100] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + maxTime: 59 + out: 6 + - name: "triangle_all" + in: + values: [2, 8, 16] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [0, 2, 10] + maxTime: 40 + out: 26 + - name: "triangle_expensive_edge" + in: + values: [2, 8, 16] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [0, 2, 100] + maxTime: 40 + out: 26 + - name: "revisit_collects_two_branches" + in: + values: [1, 10, 20] + edges: + - [0, 1, 10] + - [0, 2, 15] + maxTime: 50 + out: 31 + - name: "revisit_not_enough" + in: + values: [1, 10, 20] + edges: + - [0, 1, 10] + - [0, 2, 15] + maxTime: 39 + out: 21 + - name: "duplicate_values" + in: + values: [5, 5, 5, 5] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 0, 10] + maxTime: 80 + out: 20 + - name: "cycle_partial" + in: + values: [10, 1, 50, 3] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 0, 10] + maxTime: 39 + out: 13 + - name: "cycle_all" + in: + values: [10, 1, 50, 3] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 0, 10] + maxTime: 40 + out: 64 + - name: "weighted_shortcut" + in: + values: [1, 10, 20, 40] + edges: + - [0, 1, 10] + - [1, 2, 30] + - [2, 3, 10] + - [0, 3, 10] + maxTime: 60 + out: 71 + - name: "weighted_shortcut_tight" + in: + values: [1, 10, 20, 40] + edges: + - [0, 1, 10] + - [1, 2, 30] + - [2, 3, 10] + - [0, 3, 10] + maxTime: 40 + out: 61 + - name: "star_four_edges" + in: + values: [2, 3, 5, 7, 11] + edges: + - [0, 1, 10] + - [0, 2, 10] + - [0, 3, 10] + - [0, 4, 10] + maxTime: 80 + out: 28 + - name: "star_three_edges" + in: + values: [2, 3, 5, 7, 11] + edges: + - [0, 1, 10] + - [0, 2, 10] + - [0, 3, 10] + - [0, 4, 10] + maxTime: 60 + out: 25 + - name: "large_values" + in: + values: [100000000, 100000000, 99999999] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [0, 2, 10] + maxTime: 40 + out: 299999999 + - name: "max_time_boundary" + in: + values: [6, 7] + edges: + - [0, 1, 100] + maxTime: 100 + out: 6 + - name: "max_time_round_trip" + in: + values: [6, 7] + edges: + - [0, 1, 100] + maxTime: 100 + out: 6 + - name: "many_zero_nodes" + in: + values: [9, 0, 0, 0, 0, 25] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + - [4, 5, 10] + maxTime: 100 + out: 34 + - name: "high_leaf_unreachable" + in: + values: [2, 4, 8, 1000] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 100] + maxTime: 40 + out: 14 + - name: "parallel_route_choice" + in: + values: [1, 20, 30, 40] + edges: + - [0, 1, 10] + - [1, 3, 10] + - [0, 2, 20] + - [2, 3, 10] + - [0, 3, 10] + maxTime: 40 + out: 71 + - name: "parallel_route_tight" + in: + values: [1, 20, 30, 40] + edges: + - [0, 1, 10] + - [1, 3, 10] + - [0, 2, 20] + - [2, 3, 10] + - [0, 3, 10] + maxTime: 20 + out: 41 + - name: "five_node_cycle" + in: + values: [3, 6, 9, 12, 15] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + - [4, 0, 10] + maxTime: 100 + out: 45 + - name: "five_node_cycle_partial" + in: + values: [3, 6, 9, 12, 15] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + - [4, 0, 10] + maxTime: 60 + out: 45 + - name: "dense_bounded_degree" + in: + values: [1, 2, 4, 8, 16, 32, 64, 128] + edges: + - [0, 1, 10] + - [0, 2, 20] + - [0, 3, 30] + - [1, 4, 10] + - [1, 5, 20] + - [2, 5, 10] + - [2, 6, 20] + - [3, 6, 10] + - [3, 7, 20] + - [4, 5, 10] + - [5, 6, 10] + - [6, 7, 10] + maxTime: 100 + out: 251 + - name: "isolated_start_with_components" + in: + values: [42, 1, 2, 3, 4] + edges: + - [1, 2, 10] + - [2, 3, 10] + - [3, 4, 10] + maxTime: 100 + out: 42 + - name: "minimum_edge_time" + in: + values: [1, 2, 4] + edges: + - [0, 1, 10] + - [1, 2, 10] + maxTime: 30 + out: 3 + - name: "all_values_zero" + in: + values: [0, 0, 0, 0] + edges: + - [0, 1, 10] + - [1, 2, 10] + - [2, 3, 10] + maxTime: 100 + out: 0 diff --git a/tests/2001-2500/2065. maximum-path-quality-of-a-graph/sol.py b/tests/2001-2500/2065. maximum-path-quality-of-a-graph/sol.py new file mode 100644 index 00000000..8b579702 --- /dev/null +++ b/tests/2001-2500/2065. maximum-path-quality-of-a-graph/sol.py @@ -0,0 +1,31 @@ +class Solution: + def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int: + + def dfs(node:int, prev_qual:int, prev_time:int, prev_mask:int)-> None: + + if node == 0: + self.maxQuality = max(self.maxQuality, prev_qual) + + for nxt, wgt in graph[node]: + if wgt > prev_time: continue + + if prev_mask & (1<< nxt): qual = prev_qual + else: qual = prev_qual + values[nxt] + + mask = prev_mask | (1<< nxt) + time = prev_time - wgt + + dfs(nxt, qual, time, mask) + + return + + + self.maxQuality = 0 + graph = defaultdict(list) + + for u, v, wgt in edges: + graph[u].append((v, wgt)) + graph[v].append((u, wgt)) + + dfs(0, values[0], maxTime, 1) + return self.maxQuality \ No newline at end of file diff --git a/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/manifest.yaml b/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/manifest.yaml new file mode 100644 index 00000000..b1a17e40 --- /dev/null +++ b/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/manifest.yaml @@ -0,0 +1,256 @@ +entry: + id: 2068 + title: "check-whether-two-strings-are-almost-equivalent" + params: + word1: + type: string + word2: + type: string + call: + cpp: "Solution().checkAlmostEquivalent({word1}, {word2})" + rust: "Solution::check_almost_equivalent({word1}, {word2})" + python3: "Solution().checkAlmostEquivalent({word1}, {word2})" + python2: "Solution().checkAlmostEquivalent({word1}, {word2})" + ruby: "check_almost_equivalent({word1}, {word2})" + java: "new Solution().checkAlmostEquivalent({word1}, {word2})" + csharp: "new Solution().CheckAlmostEquivalent({word1}, {word2})" + kotlin: "Solution().checkAlmostEquivalent({word1}, {word2})" + go: "checkAlmostEquivalent({word1}, {word2})" + dart: "Solution().checkAlmostEquivalent({word1}, {word2})" + swift: "Solution().checkAlmostEquivalent({word1}, {word2})" + typescript: "checkAlmostEquivalent({word1}, {word2})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().checkAlmostEquivalent(word1, word2, {result})" + checker: | + class Checker: + def checkAlmostEquivalent(self, word1, word2, result): + expected = all(abs(word1.count(ch) - word2.count(ch)) <= 3 for ch in "abcdefghijklmnopqrstuvwxyz") + return isinstance(result, bool) and result == expected + +seed: 2068 + +tests: + - name: "example_1" + in: + word1: "aaaa" + word2: "bccb" + out: false + - name: "example_2" + in: + word1: "abcdeef" + word2: "abaaacc" + out: true + - name: "example_3" + in: + word1: "cccddabba" + word2: "babababab" + out: true + - name: "single_same" + in: + word1: "a" + word2: "a" + out: true + - name: "single_different" + in: + word1: "a" + word2: "z" + out: true + - name: "four_vs_zero" + in: + word1: "aaaa" + word2: "bbbb" + out: false + - name: "boundary_difference_three" + in: + word1: "aaaa" + word2: "abbb" + out: true + - name: "boundary_difference_four" + in: + word1: "aaaaa" + word2: "bbbbb" + out: false + - name: "identical_repeated" + in: + word1: "zzzzzzzz" + word2: "zzzzzzzz" + out: true + - name: "same_counts_reordered" + in: + word1: "aabbcc" + word2: "ccbbaa" + out: true + - name: "two_letters_balanced" + in: + word1: "abababab" + word2: "babababa" + out: true + - name: "one_letter_shifted" + in: + word1: "aaaaab" + word2: "bbbbba" + out: false + - name: "multiple_boundary_letters" + in: + word1: "aaaabbbbcccc" + word2: "bbbbccccdddd" + out: false + - name: "multiple_over_limit" + in: + word1: "aaaaabbbbb" + word2: "cccccccccc" + out: false + - name: "all_alphabet_same" + in: + word1: "abcdefghijklmnopqrstuvwxyz" + word2: "zyxwvutsrqponmlkjihgfedcba" + out: true + - name: "all_alphabet_extra_a" + in: + word1: "aabcdefghijklmnopqrstuvwxyz" + word2: "abcdefghijklmnopqrstuvwxyz" + out: true + - name: "all_alphabet_extra_a_four" + in: + word1: "aaaaabcdefghijklmnopqrstuvwxyz" + word2: "abcdefghijklmnopqrstuvwxyz" + out: false + - name: "rare_letters_disjoint" + in: + word1: "abcdefghijklmnop" + word2: "qrstuvwxyzabcdef" + out: true + - name: "long_uniform_equal" + in: + word1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + word2: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + out: true + - name: "long_uniform_different" + in: + word1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + word2: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + out: false + - name: "length_two" + in: + word1: "ab" + word2: "cd" + out: true + - name: "length_three_extremes" + in: + word1: "aaa" + word2: "bbb" + out: true + - name: "length_four_extremes" + in: + word1: "aaaa" + word2: "bbbb" + out: false + - name: "nested_frequency_boundary" + in: + word1: "aaaaabbb" + word2: "aabbbccc" + out: true + - name: "nested_frequency_failure" + in: + word1: "aaaaaabb" + word2: "abbbbbbb" + out: false + - name: "late_alphabet_letters" + in: + word1: "uuuuuvvvvwwwwxxyyzz" + word2: "uuuvvvwwwxxxyyyyzz" + out: true + - name: "case_lowercase_only" + in: + word1: "mnopq" + word2: "rrrrr" + out: false + - name: "one_char_over_limit_with_noise" + in: + word1: "aaaaabbbbbcc" + word2: "abbbbbbbbbcc" + out: false + - name: "balanced_noise" + in: + word1: "aabbccddeeff" + word2: "ffeeddccbbaa" + out: true + - name: "disjoint_four_each" + in: + word1: "aaaabbbb" + word2: "ccccdddd" + out: false + - name: "frequency_three_each" + in: + word1: "aaabbbccc" + word2: "dddeeefff" + out: true + - name: "frequency_four_each" + in: + word1: "aaaabbbbcccc" + word2: "ddddeeeeffff" + out: false + - name: "generated_uniform_alphabet" + seed: 101 + in: + word1: + gen: "str" + len: 100 + alphabet: "abcd" + word2: + gen: "str" + len: 100 + alphabet: "abcd" + - name: "generated_full_alphabet" + seed: 202 + in: + word1: + gen: "str" + len: 100 + alphabet: "abcdefghijklmnopqrstuvwxyz" + word2: + gen: "str" + len: 100 + alphabet: "abcdefghijklmnopqrstuvwxyz" + - name: "generated_binary_alphabet" + seed: 303 + in: + word1: + gen: "str" + len: 100 + alphabet: "mn" + word2: + gen: "str" + len: 100 + alphabet: "mn" + - name: "generated_sparse_alphabet" + seed: 404 + in: + word1: + gen: "str" + len: 100 + alphabet: "az" + word2: + gen: "str" + len: 100 + alphabet: "az" + - name: "generated_mid_alphabet" + seed: 505 + in: + word1: + gen: "str" + len: 100 + alphabet: "ghijklmnopqr" + word2: + gen: "str" + len: 100 + alphabet: "ghijklmnopqr" diff --git a/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/sol.py b/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/sol.py new file mode 100644 index 00000000..a84968a6 --- /dev/null +++ b/tests/2001-2500/2068. check-whether-two-strings-are-almost-equivalent/sol.py @@ -0,0 +1,13 @@ +class Solution(object): + def checkAlmostEquivalent(self, word1, word2): + d1 = {} + for i in word1: + d1[i] = d1.get(i, 0) + 1 + d2 = {} + for i in word2: + d2[i] = d2.get(i, 0) + 1 + a = set(word1) | set(word2) + for i in a: + if abs(d1.get(i, 0) - d2.get(i, 0)) > 3: + return False + return True \ No newline at end of file diff --git a/tests/2001-2500/2069. walking-robot-simulation-ii/sol.py b/tests/2001-2500/2069. walking-robot-simulation-ii/sol.py new file mode 100644 index 00000000..3b30cdeb --- /dev/null +++ b/tests/2001-2500/2069. walking-robot-simulation-ii/sol.py @@ -0,0 +1,44 @@ +class Solution: + # Added using AI + class Robot: + def __init__(self, width: int, height: int): + self.x = 0 + self.y = 0 + self.dir = "East" + self.width = width + self.height = height + + def step(self, num: int) -> None: + perim = 2 * (self.width - 1) + 2 * (self.height - 1) + num %= perim + if num == 0: + num = perim + + while num > 0: + if self.dir == "East": + maxX = min(self.x + num, self.width - 1) + rem = num - (maxX - self.x) + num = rem + if rem == 0: self.x = maxX + else: self.x = maxX; self.dir = "North" + elif self.dir == "West": + minX = max(self.x - num, 0) + rem = num - (self.x - minX) + num = rem + if rem == 0: self.x = minX + else: self.x = minX; self.dir = "South" + elif self.dir == "North": + maxY = min(self.y + num, self.height - 1) + rem = num - (maxY - self.y) + num = rem + if rem == 0: self.y = maxY + else: self.y = maxY; self.dir = "West" + elif self.dir == "South": + minY = max(self.y - num, 0) + rem = num - (self.y - minY) + num = rem + if rem == 0: self.y = minY + else: self.y = minY; self.dir = "East" + + def getPos(self): return [self.x, self.y] + def getDir(self): return self.dir diff --git a/tests/2001-2500/2070. most-beautiful-item-for-each-query/manifest.yaml b/tests/2001-2500/2070. most-beautiful-item-for-each-query/manifest.yaml new file mode 100644 index 00000000..599847fc --- /dev/null +++ b/tests/2001-2500/2070. most-beautiful-item-for-each-query/manifest.yaml @@ -0,0 +1,515 @@ +entry: + id: 2070 + title: "most-beautiful-item-for-each-query" + params: + items: + type: array + items: + type: array + items: + type: int + queries: + type: array + items: + type: int + call: + cpp: "Solution().maximumBeauty({items}, {queries})" + rust: "Solution::maximum_beauty({items}, {queries})" + python3: "Solution().maximumBeauty({items}, {queries})" + python2: "Solution().maximumBeauty({items}, {queries})" + ruby: "maximum_beauty({items}, {queries})" + java: "new Solution().maximumBeauty({items}, {queries})" + csharp: "new Solution().MaximumBeauty({items}, {queries})" + kotlin: "Solution().maximumBeauty({items}, {queries})" + go: "maximumBeauty({items}, {queries})" + dart: "Solution().maximumBeauty({items}, {queries})" + swift: "Solution().maximumBeauty({items}, {queries})" + typescript: "maximumBeauty({items}, {queries})" + +judge: + type: "exact" + +limits: + time_ms: 5000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maximumBeauty(items, queries, {result})" + checker: | + from bisect import bisect_right + + class Checker: + def maximumBeauty(self, items, queries, result): + if not isinstance(result, list) or len(result) != len(queries): + return False + ordered = sorted(items) + prices = [] + prefix = [] + for price, beauty in ordered: + prices.append(price) + prefix.append(max(beauty, prefix[-1] if prefix else 0)) + expected = [prefix[bisect_right(prices, query) - 1] + if bisect_right(prices, query) else 0 + for query in queries] + return result == expected + +seed: 207000 + +tests: + - name: "example_1" + in: + items: + elemType: "int" + value: + - [1, 2] + - [3, 2] + - [2, 4] + - [5, 6] + - [3, 5] + queries: [1, 2, 3, 4, 5, 6] + out: [2, 4, 5, 5, 6, 6] + - name: "example_2_duplicate_prices" + in: + items: + elemType: "int" + value: + - [1, 2] + - [1, 2] + - [1, 3] + - [1, 4] + queries: [1] + out: [4] + - name: "example_3_no_eligible_item" + in: + items: + elemType: "int" + value: + - [10, 1000] + queries: [5] + out: [0] + - name: "single_exact_match" + in: + items: + elemType: "int" + value: + - [7, 11] + queries: [7] + out: [11] + - name: "single_below_and_above" + in: + items: + elemType: "int" + value: + - [7, 11] + queries: [1, 6, 8, 100] + out: [0, 0, 11, 11] + - name: "query_order_preserved" + in: + items: + elemType: "int" + value: + - [2, 20] + - [5, 50] + - [9, 90] + queries: [9, 1, 5, 10, 2, 8] + out: [90, 0, 50, 90, 20, 50] + - name: "same_price_increasing_beauty" + in: + items: + elemType: "int" + value: + - [4, 1] + - [4, 9] + - [4, 3] + queries: [3, 4, 5] + out: [0, 9, 9] + - name: "same_price_decreasing_beauty" + in: + items: + elemType: "int" + value: + - [4, 10] + - [4, 8] + - [4, 2] + queries: [4] + out: [10] + - name: "unsorted_items" + in: + items: + elemType: "int" + value: + - [10, 1] + - [1, 100] + - [7, 50] + - [3, 25] + queries: [1, 2, 3, 6, 7, 10] + out: [100, 100, 100, 100, 100, 100] + - name: "beauty_peak_then_lower" + in: + items: + elemType: "int" + value: + - [1, 5] + - [2, 100] + - [3, 20] + - [4, 7] + queries: [1, 2, 3, 4] + out: [5, 100, 100, 100] + - name: "strict_price_boundaries" + in: + items: + elemType: "int" + value: + - [5, 50] + - [10, 100] + queries: [4, 5, 6, 9, 10, 11] + out: [0, 50, 50, 50, 100, 100] + - name: "all_queries_before_items" + in: + items: + elemType: "int" + value: + - [100, 1] + - [200, 2] + queries: [1, 50, 99] + out: [0, 0, 0] + - name: "all_queries_after_items" + in: + items: + elemType: "int" + value: + - [2, 8] + - [4, 3] + - [6, 15] + queries: [7, 8, 100] + out: [15, 15, 15] + - name: "one_query_many_items" + in: + items: + elemType: "int" + value: + - [8, 80] + - [1, 10] + - [5, 55] + - [3, 30] + - [5, 60] + queries: [5] + out: [60] + - name: "many_queries_one_item" + in: + items: + elemType: "int" + value: + - [50, 77] + queries: [1, 49, 50, 51, 1000000000] + out: [0, 0, 77, 77, 77] + - name: "maximum_values" + in: + items: + elemType: "int" + value: + - [1000000000, 1000000000] + - [999999999, 999999998] + queries: [999999998, 999999999, 1000000000] + out: [0, 999999998, 1000000000] + - name: "minimum_values" + in: + items: + elemType: "int" + value: + - [1, 1] + - [2, 1] + queries: [1, 2] + out: [1, 1] + - name: "duplicate_items" + in: + items: + elemType: "int" + value: + - [2, 5] + - [2, 5] + - [2, 5] + - [3, 6] + queries: [1, 2, 3] + out: [0, 5, 6] + - name: "interleaved_prices" + in: + items: + elemType: "int" + value: + - [20, 2] + - [4, 40] + - [12, 12] + - [8, 80] + - [16, 16] + queries: [4, 8, 12, 16, 20] + out: [40, 80, 80, 80, 80] + - name: "equal_query_repetition" + in: + items: + elemType: "int" + value: + - [3, 9] + - [6, 2] + - [9, 12] + queries: [6, 6, 6, 3, 3] + out: [9, 9, 9, 9, 9] + - name: "large_beauty_before_small_beauty" + in: + items: + elemType: "int" + value: + - [2, 999] + - [100, 1] + - [50, 500] + queries: [1, 2, 49, 50, 100] + out: [0, 999, 999, 999, 999] + - name: "all_prices_equal_large_beauties" + in: + items: + elemType: "int" + value: + - [42, 3] + - [42, 300] + - [42, 30] + - [42, 299] + queries: [41, 42, 43] + out: [0, 300, 300] + - name: "alternating_query_thresholds" + in: + items: + elemType: "int" + value: + - [10, 10] + - [20, 30] + - [30, 20] + queries: [30, 10, 29, 20, 9, 31] + out: [30, 10, 30, 30, 0, 30] + - name: "long_price_gaps" + in: + items: + elemType: "int" + value: + - [1, 7] + - [1000000000, 8] + queries: [1, 2, 999999999, 1000000000] + out: [7, 7, 7, 8] + - name: "beauty_zero_not_allowed_but_default_zero" + in: + items: + elemType: "int" + value: + - [500, 1] + - [600, 2] + queries: [1, 499, 500] + out: [0, 0, 1] + - name: "query_at_each_duplicate_price" + in: + items: + elemType: "int" + value: + - [3, 4] + - [3, 9] + - [5, 2] + - [5, 10] + - [7, 8] + queries: [2, 3, 4, 5, 6, 7] + out: [0, 9, 9, 10, 10, 10] + - name: "reverse_sorted_items" + in: + items: + elemType: "int" + value: + - [9, 90] + - [7, 70] + - [5, 50] + - [3, 30] + - [1, 10] + queries: [0, 1, 4, 5, 8, 9] + out: [0, 10, 30, 50, 70, 90] + - name: "mixed_duplicate_and_unordered" + in: + items: + elemType: "int" + value: + - [8, 1] + - [2, 20] + - [8, 80] + - [4, 40] + - [2, 15] + - [6, 60] + queries: [2, 3, 4, 7, 8] + out: [20, 20, 40, 60, 80] + - name: "powers_of_two" + in: + items: + elemType: "int" + value: + - [1, 2] + - [2, 4] + - [4, 8] + - [8, 16] + - [16, 32] + queries: [1, 3, 7, 15, 31, 32] + out: [2, 4, 8, 16, 32, 32] + - name: "descending_beauties" + in: + items: + elemType: "int" + value: + - [1, 100] + - [2, 90] + - [3, 80] + - [4, 70] + queries: [1, 2, 3, 4] + out: [100, 100, 100, 100] + - name: "ascending_beauties" + in: + items: + elemType: "int" + value: + - [4, 40] + - [1, 10] + - [3, 30] + - [2, 20] + queries: [1, 2, 3, 4] + out: [10, 20, 30, 40] + - name: "single_item_extremes" + in: + items: + elemType: "int" + value: + - [1000000000, 1000000000] + queries: [1, 999999999, 1000000000] + out: [0, 0, 1000000000] + - name: "generated_small_general" + seed: 207001 + in: + items: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 1000000000 + queries: + gen: "array" + len: + gen: "int" + min: 1 + max: 40 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_medium_general" + seed: 207002 + in: + items: + gen: "array" + len: + gen: "int" + min: 400 + max: 700 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 1000000000 + queries: + gen: "array" + len: + gen: "int" + min: 400 + max: 700 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_large_items" + seed: 207003 + in: + items: + gen: "array" + len: + gen: "int" + min: 80000 + max: 80000 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 1000000000 + queries: + gen: "array" + len: + gen: "int" + min: 50000 + max: 50000 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_maximum_scale" + seed: 207004 + in: + items: + gen: "array" + len: + gen: "int" + min: 100000 + max: 100000 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 1000000000 + queries: + gen: "array" + len: + gen: "int" + min: 100000 + max: 100000 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_duplicate_friendly" + seed: 207005 + in: + items: + gen: "array" + len: + gen: "int" + min: 1000 + max: 1500 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 20 + queries: + gen: "array" + len: + gen: "int" + min: 1000 + max: 1500 + of: + gen: "int" + min: 1 + max: 20 diff --git a/tests/2001-2500/2070. most-beautiful-item-for-each-query/sol.py b/tests/2001-2500/2070. most-beautiful-item-for-each-query/sol.py new file mode 100644 index 00000000..4fd3cb5d --- /dev/null +++ b/tests/2001-2500/2070. most-beautiful-item-for-each-query/sol.py @@ -0,0 +1,28 @@ +class Solution: + def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]: + + items.sort() + + for i in range(1, len(items)): + items[i][1] = max(items[i][1], items[i - 1][1]) + + ans = [] + + for q in queries: + + l, h = 0, len(items) - 1 + beauty = 0 + + while l <= h: + + mid = (l + h) // 2 + + if items[mid][0] <= q: + beauty = items[mid][1] + l = mid + 1 + else: + h = mid - 1 + + ans.append(beauty) + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/manifest.yaml b/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/manifest.yaml new file mode 100644 index 00000000..09c6f126 --- /dev/null +++ b/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/manifest.yaml @@ -0,0 +1,443 @@ +entry: + id: 2071 + title: "maximum-number-of-tasks-you-can-assign" + params: + tasks: + type: array + items: + type: int + workers: + type: array + items: + type: int + pills: + type: int + strength: + type: int + call: + cpp: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + rust: "Solution::max_task_assign({tasks}, {workers}, {pills}, {strength})" + python3: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + python2: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + ruby: "max_task_assign({tasks}, {workers}, {pills}, {strength})" + java: "new Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + csharp: "new Solution().MaxTaskAssign({tasks}, {workers}, {pills}, {strength})" + kotlin: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + go: "maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + dart: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + swift: "Solution().maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + typescript: "maxTaskAssign({tasks}, {workers}, {pills}, {strength})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maxTaskAssign(tasks, workers, pills, strength, {result})" + checker: | + class Checker: + def maxTaskAssign(self, tasks, workers, pills, strength, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + if result < 0 or result > min(len(tasks), len(workers)): + return False + a = sorted(tasks) + w = sorted(workers) + def possible(k): + pool = w[-k:] + used = 0 + for task in reversed(a[:k]): + if pool and pool[-1] >= task: + pool.pop() + else: + i = 0 + while i < len(pool) and pool[i] + strength < task: + i += 1 + if i == len(pool) or used == pills: + return False + used += 1 + pool.pop(i) + return True + lo, hi = 0, min(len(a), len(w)) + while lo < hi: + mid = (lo + hi + 1) // 2 + if possible(mid): + lo = mid + else: + hi = mid - 1 + return result == lo + +seed: 2071 + +tests: + - name: "example_1" + in: + tasks: [3, 2, 1] + workers: [0, 3, 3] + pills: 1 + strength: 1 + out: 3 + - name: "example_2" + in: + tasks: [5, 4] + workers: [0, 0, 0] + pills: 1 + strength: 5 + out: 1 + - name: "example_3" + in: + tasks: [10, 15, 30] + workers: [0, 10, 10, 10, 10] + pills: 3 + strength: 10 + out: 2 + - name: "one_exact_worker" + in: + tasks: [7] + workers: [7] + pills: 0 + strength: 0 + out: 1 + - name: "one_needs_pill" + in: + tasks: [8] + workers: [7] + pills: 1 + strength: 1 + out: 1 + - name: "one_impossible" + in: + tasks: [8] + workers: [7] + pills: 0 + strength: 1 + out: 0 + - name: "no_pills_direct_matches" + in: + tasks: [1, 2, 3, 4] + workers: [0, 2, 3, 4, 5] + pills: 0 + strength: 9 + out: 4 + - name: "all_pills_equal_count" + in: + tasks: [5, 6, 7] + workers: [1, 2, 3] + pills: 3 + strength: 4 + out: 3 + - name: "pills_zero_strength" + in: + tasks: [0, 0, 1] + workers: [0, 0, 0] + pills: 2 + strength: 0 + out: 2 + - name: "zero_requirements" + in: + tasks: [0, 0, 0, 0] + workers: [0, 0] + pills: 0 + strength: 0 + out: 2 + - name: "more_workers_than_tasks" + in: + tasks: [4, 8] + workers: [1, 4, 8, 100] + pills: 0 + strength: 20 + out: 2 + - name: "more_tasks_than_workers" + in: + tasks: [1, 2, 3, 4, 5] + workers: [5, 5] + pills: 0 + strength: 1 + out: 2 + - name: "duplicates_and_one_pill" + in: + tasks: [5, 5, 5, 5] + workers: [4, 4, 5, 5] + pills: 1 + strength: 1 + out: 3 + - name: "pill_must_help_weakest" + in: + tasks: [4, 9] + workers: [3, 8] + pills: 1 + strength: 1 + out: 1 + - name: "pill_not_enough" + in: + tasks: [4, 9] + workers: [3, 8] + pills: 1 + strength: 0 + out: 1 + - name: "large_strength_value" + in: + tasks: [1000000000, 999999999] + workers: [999999998, 1000000000] + pills: 1 + strength: 1 + out: 2 + - name: "large_gap" + in: + tasks: [1000000000] + workers: [0] + pills: 1 + strength: 999999999 + out: 0 + - name: "boundary_pill_count" + in: + tasks: [2, 3, 4, 5] + workers: [1, 1, 1, 1] + pills: 4 + strength: 4 + out: 4 + - name: "direct_preferred_over_pill" + in: + tasks: [2, 100] + workers: [2, 99] + pills: 1 + strength: 1 + out: 2 + - name: "only_hard_task_fails" + in: + tasks: [1, 2, 100] + workers: [1, 2, 2] + pills: 1 + strength: 50 + out: 2 + - name: "descending_inputs" + in: + tasks: [9, 7, 5, 3] + workers: [8, 6, 4, 2] + pills: 2 + strength: 1 + out: 3 + - name: "interleaved_capabilities" + in: + tasks: [4, 4, 7, 8] + workers: [3, 5, 6, 7] + pills: 2 + strength: 1 + out: 3 + - name: "zero_pills_zero_strength" + in: + tasks: [0, 1, 2] + workers: [0, 1, 1] + pills: 0 + strength: 0 + out: 2 + - name: "all_workers_too_weak" + in: + tasks: [10, 20, 30] + workers: [0, 1, 2] + pills: 0 + strength: 5 + out: 0 + - name: "all_workers_with_pills" + in: + tasks: [10, 20, 30] + workers: [0, 10, 20] + pills: 3 + strength: 10 + out: 3 + - name: "exact_boundary_without_pill" + in: + tasks: [10, 20] + workers: [10, 19] + pills: 0 + strength: 1 + out: 1 + - name: "pill_boundary_inclusive" + in: + tasks: [10, 20] + workers: [9, 19] + pills: 2 + strength: 1 + out: 2 + - name: "one_worker_many_tasks" + in: + tasks: [0, 0, 1, 2] + workers: [1] + pills: 1 + strength: 1 + out: 1 + - name: "one_task_many_workers" + in: + tasks: [50] + workers: [0, 25, 49, 50] + pills: 0 + strength: 50 + out: 1 + - name: "all_equal" + in: + tasks: [6, 6, 6, 6] + workers: [6, 6, 6, 6] + pills: 0 + strength: 0 + out: 4 + - name: "pill_budget_bottleneck" + in: + tasks: [5, 6, 7] + workers: [4, 5, 6] + pills: 1 + strength: 1 + out: 2 + - name: "worker_count_bottleneck" + in: + tasks: [1, 2, 3, 4] + workers: [1, 2] + pills: 2 + strength: 100 + out: 2 + - name: "large_repeated_tasks" + in: + tasks: [1000000000, 1000000000, 1000000000] + workers: [999999999, 999999999, 999999999] + pills: 2 + strength: 1 + out: 2 + - name: "mixed_zero_and_max" + in: + tasks: [0, 1000000000] + workers: [0, 999999999] + pills: 1 + strength: 1 + out: 2 + - name: "many_workers_low_pills" + in: + tasks: [3, 4, 5, 6, 7, 8] + workers: [1, 2, 3, 4, 5, 6, 7, 8] + pills: 1 + strength: 1 + out: 6 + - name: "generated_small" + seed: 301 + in: + tasks: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "int" + min: 0 + max: 100 + workers: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "int" + min: 0 + max: 100 + pills: + gen: "int" + min: 0 + max: 30 + strength: + gen: "int" + min: 0 + max: 100 + - name: "generated_medium" + seed: 302 + in: + tasks: + gen: "array" + len: 250 + of: + gen: "int" + min: 0 + max: 100000 + workers: + gen: "array" + len: 250 + of: + gen: "int" + min: 0 + max: 100000 + pills: + gen: "int" + min: 0 + max: 250 + strength: + gen: "int" + min: 0 + max: 100000 + - name: "generated_unequal" + seed: 303 + in: + tasks: + gen: "array" + len: 1000 + of: + gen: "int" + min: 0 + max: 1000000000 + workers: + gen: "array" + len: 700 + of: + gen: "int" + min: 0 + max: 1000000000 + pills: + gen: "int" + min: 0 + max: 700 + strength: + gen: "int" + min: 0 + max: 1000000000 + - name: "generated_large_tasks" + seed: 304 + in: + tasks: + gen: "array" + len: 50000 + of: + gen: "int" + min: 0 + max: 1000000000 + workers: + gen: "array" + len: 50000 + of: + gen: "int" + min: 0 + max: 1000000000 + pills: 25000 + strength: + gen: "int" + min: 0 + max: 1000000000 + - name: "generated_maximum" + seed: 305 + in: + tasks: + gen: "array" + len: 50000 + of: + gen: "int" + min: 0 + max: 1000000000 + workers: + gen: "array" + len: 50000 + of: + gen: "int" + min: 0 + max: 1000000000 + pills: 50000 + strength: 1000000000 diff --git a/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/sol.py b/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/sol.py new file mode 100644 index 00000000..46e0a8bc --- /dev/null +++ b/tests/2001-2500/2071. maximum-number-of-tasks-you-can-assign/sol.py @@ -0,0 +1,29 @@ +class Solution(object): + def maxTaskAssign(self, tasks, workers, pills, strength): + tasks.sort() + workers.sort() + left, right = 0, min(len(tasks), len(workers)) + + while left < right: + mid = (left + right + 1)//2 + usedPills = 0 + avail = workers[-mid:] + canAssign = True + + for t in reversed(tasks[:mid]): + if avail[-1] >= t: + avail.pop() + else: + idx = bisect.bisect_left(avail, t - strength) + if idx == len(avail) or usedPills == pills: + canAssign = False + break + usedPills += 1 + avail.pop(idx) + + if canAssign: + left = mid + else: + right = mid - 1 + + return left \ No newline at end of file diff --git a/tests/2001-2500/2073. time-needed-to-buy-tickets/manifest.yaml b/tests/2001-2500/2073. time-needed-to-buy-tickets/manifest.yaml new file mode 100644 index 00000000..aa51c011 --- /dev/null +++ b/tests/2001-2500/2073. time-needed-to-buy-tickets/manifest.yaml @@ -0,0 +1,272 @@ +entry: + id: 2073 + title: "time-needed-to-buy-tickets" + params: + tickets: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().timeRequiredToBuy({tickets}, {k})" + rust: "Solution::time_required_to_buy({tickets}, {k})" + python3: "Solution().timeRequiredToBuy({tickets}, {k})" + python2: "Solution().timeRequiredToBuy({tickets}, {k})" + ruby: "time_required_to_buy({tickets}, {k})" + java: "new Solution().timeRequiredToBuy({tickets}, {k})" + csharp: "new Solution().TimeRequiredToBuy({tickets}, {k})" + kotlin: "Solution().timeRequiredToBuy({tickets}, {k})" + go: "timeRequiredToBuy({tickets}, {k})" + dart: "Solution().timeRequiredToBuy({tickets}, {k})" + swift: "Solution().timeRequiredToBuy({tickets}, {k})" + typescript: "timeRequiredToBuy({tickets}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().timeRequiredToBuy(tickets, k, {result})" + checker: | + class Checker: + def timeRequiredToBuy(self, tickets, k, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + target = tickets[k] + expected = 0 + for i, count in enumerate(tickets): + expected += min(count, target if i <= k else target - 1) + return result == expected + +seed: 2073 + +tests: + - name: "example_one" + in: + tickets: [2, 3, 2] + k: 2 + out: 6 + - name: "example_two" + in: + tickets: [5, 1, 1, 1] + k: 0 + out: 8 + - name: "single_person_minimum" + in: + tickets: [1] + k: 0 + out: 1 + - name: "single_person_maximum" + in: + tickets: [100] + k: 0 + out: 100 + - name: "target_front_all_minimum" + in: + tickets: [1, 1, 1, 1, 1] + k: 0 + out: 1 + - name: "target_back_all_minimum" + in: + tickets: [1, 1, 1, 1, 1] + k: 4 + out: 5 + - name: "target_front_all_maximum" + in: + tickets: [100, 100, 100] + k: 0 + out: 298 + - name: "target_back_all_maximum" + in: + tickets: [100, 100, 100] + k: 2 + out: 300 + - name: "target_front_large_others_small" + in: + tickets: [100, 1, 1, 1, 1] + k: 0 + out: 104 + - name: "target_back_large_others_small" + in: + tickets: [1, 1, 1, 1, 100] + k: 4 + out: 104 + - name: "target_middle_large" + in: + tickets: [1, 1, 100, 1, 1] + k: 2 + out: 104 + - name: "target_middle_small_others_large" + in: + tickets: [100, 100, 1, 100, 100] + k: 2 + out: 3 + - name: "two_people_front_equal" + in: + tickets: [7, 7] + k: 0 + out: 13 + - name: "two_people_back_equal" + in: + tickets: [7, 7] + k: 1 + out: 14 + - name: "two_people_skew_front" + in: + tickets: [3, 10] + k: 0 + out: 5 + - name: "two_people_skew_back" + in: + tickets: [10, 3] + k: 1 + out: 6 + - name: "alternating_counts_front" + in: + tickets: [4, 1, 4, 1, 4, 1] + k: 0 + out: 13 + - name: "alternating_counts_middle" + in: + tickets: [4, 1, 4, 1, 4, 1] + k: 2 + out: 14 + - name: "alternating_counts_back" + in: + tickets: [4, 1, 4, 1, 4, 1] + k: 5 + out: 6 + - name: "increasing_target_front" + in: + tickets: [1, 2, 3, 4, 5] + k: 0 + out: 1 + - name: "increasing_target_middle" + in: + tickets: [1, 2, 3, 4, 5] + k: 2 + out: 10 + - name: "increasing_target_back" + in: + tickets: [1, 2, 3, 4, 5] + k: 4 + out: 15 + - name: "decreasing_target_front" + in: + tickets: [5, 4, 3, 2, 1] + k: 0 + out: 15 + - name: "decreasing_target_middle" + in: + tickets: [5, 4, 3, 2, 1] + k: 2 + out: 12 + - name: "decreasing_target_back" + in: + tickets: [5, 4, 3, 2, 1] + k: 4 + out: 5 + - name: "mixed_small_front" + in: + tickets: [2, 5, 1, 4, 3] + k: 0 + out: 6 + - name: "mixed_small_second" + in: + tickets: [2, 5, 1, 4, 3] + k: 1 + out: 15 + - name: "mixed_small_fourth" + in: + tickets: [2, 5, 1, 4, 3] + k: 3 + out: 14 + - name: "mixed_small_back" + in: + tickets: [2, 5, 1, 4, 3] + k: 4 + out: 12 + - name: "repeated_peak_before_target" + in: + tickets: [8, 8, 2, 8, 1] + k: 2 + out: 8 + - name: "repeated_peak_after_target" + in: + tickets: [2, 8, 8, 8, 1] + k: 2 + out: 26 + - name: "boundary_values_mixed" + in: + tickets: [1, 100, 1, 100, 1, 100] + k: 3 + out: 302 + - name: "generated_small_uniform" + seed: 101 + in: + tickets: + gen: "array" + len: 8 + of: + gen: "int" + min: 1 + max: 10 + k: + gen: "int" + min: 0 + max: 7 + - name: "generated_medium_varied" + seed: 202 + in: + tickets: + gen: "array" + len: 37 + of: + gen: "int" + min: 1 + max: 100 + k: + gen: "int" + min: 0 + max: 36 + - name: "generated_maximum_front" + seed: 303 + in: + tickets: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + k: 0 + - name: "generated_maximum_back" + seed: 404 + in: + tickets: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + k: 99 + - name: "generated_maximum_middle" + seed: 505 + in: + tickets: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + k: + gen: "int" + min: 49 + max: 50 diff --git a/tests/2001-2500/2073. time-needed-to-buy-tickets/sol.py b/tests/2001-2500/2073. time-needed-to-buy-tickets/sol.py new file mode 100644 index 00000000..f6b803c3 --- /dev/null +++ b/tests/2001-2500/2073. time-needed-to-buy-tickets/sol.py @@ -0,0 +1,14 @@ +class Solution(object): + def timeRequiredToBuy(self, tickets, k): + c=0 + while tickets[k]!=0: + for i in range(len(tickets)): + if i==k: + tickets[i]-=1 + c+=1 + if tickets[k]==0: + break + elif tickets[i]!=0: + tickets[i]-=1 + c+=1 + return c \ No newline at end of file diff --git a/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/manifest.yaml b/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/manifest.yaml new file mode 100644 index 00000000..4751cf2e --- /dev/null +++ b/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/manifest.yaml @@ -0,0 +1,193 @@ +entry: + id: 2074 + title: "reverse-nodes-in-even-length-groups" + params: + head: + type: list_node + call: + cpp: "listNodeToArray(Solution().reverseEvenLengthGroups({head}))" + rust: "ListNode::list_node_to_array(Solution::reverse_even_length_groups({head}))" + python3: "list_node_to_array(Solution().reverseEvenLengthGroups({head}))" + python2: "list_node_to_array(Solution().reverseEvenLengthGroups({head}))" + ruby: "list_node_to_array(reverse_even_length_groups({head}))" + java: "ListNode.listNodeToArray(new Solution().reverseEvenLengthGroups({head}))" + csharp: "ListNode.ListNodeToArray(new Solution().ReverseEvenLengthGroups({head}))" + kotlin: "listNodeToArray(Solution().reverseEvenLengthGroups({head}))" + go: "listNodeToArray(reverseEvenLengthGroups({head}))" + dart: "list_node_to_array(Solution().reverseEvenLengthGroups({head}))" + swift: "list_node_to_array(Solution().reverseEvenLengthGroups({head}))" + typescript: "listNodeToArray(reverseEvenLengthGroups({head}))" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().reverseEvenLengthGroups(head, {result})" + checker: | + class Checker: + def reverseEvenLengthGroups(self, head, result): + if not isinstance(head, list) or not isinstance(result, list): + return False + if len(head) != len(result): + return False + expected = [] + start = 0 + size = 1 + while start < len(head): + end = min(start + size, len(head)) + group = head[start:end] + if len(group) % 2 == 0: + group.reverse() + expected.extend(group) + start = end + size += 1 + return result == expected + +seed: 20742074 + +tests: + - name: "example_1" + in: + head: [5, 2, 6, 3, 9, 1, 7, 3, 8, 4] + out: [5, 6, 2, 3, 9, 1, 4, 8, 3, 7] + - name: "example_2" + in: + head: [1, 1, 0, 6] + out: [1, 0, 1, 6] + - name: "example_3" + in: + head: [1, 1, 0, 6, 5] + out: [1, 0, 1, 5, 6] + - name: "length_1" + in: + head: [0] + out: [0] + - name: "length_2" + in: + head: [0, 1] + out: [0, 1] + - name: "length_3" + in: + head: [0, 1, 2] + out: [0, 2, 1] + - name: "length_4" + in: + head: [0, 1, 2, 3] + out: [0, 2, 1, 3] + - name: "length_5" + in: + head: [0, 1, 2, 3, 4] + out: [0, 2, 1, 4, 3] + - name: "length_6" + in: + head: [0, 1, 2, 3, 4, 5] + out: [0, 2, 1, 3, 4, 5] + - name: "length_7" + in: + head: [0, 1, 2, 3, 4, 5, 6] + out: [0, 2, 1, 3, 4, 5, 6] + - name: "length_8" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7] + out: [0, 2, 1, 3, 4, 5, 7, 6] + - name: "length_9" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8] + out: [0, 2, 1, 3, 4, 5, 6, 7, 8] + - name: "length_10" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6] + - name: "length_11" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10] + - name: "length_12" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 11, 10] + - name: "length_13" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12] + - name: "length_14" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 13, 12, 11, 10] + - name: "length_15" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14] + - name: "length_16" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 15] + - name: "length_17" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 16, 15] + - name: "length_18" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 15, 16, 17] + - name: "length_19" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 18, 17, 16, 15] + - name: "length_20" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] + - name: "length_21" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15] + - name: "length_22" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21] + - name: "length_23" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 22, 21] + - name: "length_24" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21, 22, 23] + - name: "length_25" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 24, 23, 22, 21] + - name: "length_26" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21, 22, 23, 24, 25] + - name: "length_27" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 26, 25, 24, 23, 22, 21] + - name: "length_28" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21, 22, 23, 24, 25, 26, 27] + - name: "length_29" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21, 22, 23, 24, 25, 26, 27, 28] + - name: "length_30" + in: + head: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] + out: [0, 2, 1, 3, 4, 5, 9, 8, 7, 6, 10, 11, 12, 13, 14, 20, 19, 18, 17, 16, 15, 21, 22, 23, 24, 25, 26, 27, 29, 28] + - name: "duplicates_and_zeros" + in: + head: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + out: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + - name: "maximum_values" + in: + head: [100000, 99999, 0, 100000, 1, 99998, 2, 99997, 3, 99996, 4, 99995, 5, 99994, 6, 99993, 7, 99992, 8, 99991] + out: [100000, 0, 99999, 100000, 1, 99998, 99996, 3, 99997, 2, 4, 99995, 5, 99994, 6, 99993, 7, 99992, 8, 99991] diff --git a/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/sol.py b/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/sol.py new file mode 100644 index 00000000..91358b04 --- /dev/null +++ b/tests/2001-2500/2074. reverse-nodes-in-even-length-groups/sol.py @@ -0,0 +1,47 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution(object): + def reverseEvenLengthGroups(self, head): + """ + :type head: Optional[ListNode] + :rtype: Optional[ListNode] + """ + dummy = ListNode(0) + dummy.next = head + + group_size = 1 + prev = dummy + curr = head + + while curr: + count = 0 + temp = curr + while temp and count < group_size: + temp = temp.next + count += 1 + + if count % 2 == 0: + prev_next = prev.next + node = curr + prev_node = None + for _ in range(count): + nxt = node.next + node.next = prev_node + prev_node = node + node = nxt + + prev.next = prev_node + prev_next.next = node + prev = prev_next + curr = node + else: + for _ in range(count): + prev = curr + curr = curr.next + + group_size += 1 + + return dummy.next \ No newline at end of file diff --git a/tests/2001-2500/2075. decode-the-slanted-ciphertext/manifest.yaml b/tests/2001-2500/2075. decode-the-slanted-ciphertext/manifest.yaml new file mode 100644 index 00000000..14dcab12 --- /dev/null +++ b/tests/2001-2500/2075. decode-the-slanted-ciphertext/manifest.yaml @@ -0,0 +1,227 @@ +entry: + id: 2075 + title: "decode-the-slanted-ciphertext" + params: + encodedText: + type: string + rows: + type: int + call: + cpp: "Solution().decodeCiphertext({encodedText}, {rows})" + rust: "Solution::decode_ciphertext({encodedText}, {rows})" + python3: "Solution().decodeCiphertext({encodedText}, {rows})" + python2: "Solution().decodeCiphertext({encodedText}, {rows})" + ruby: "decode_ciphertext({encodedText}, {rows})" + java: "new Solution().decodeCiphertext({encodedText}, {rows})" + csharp: "new Solution().DecodeCiphertext({encodedText}, {rows})" + kotlin: "Solution().decodeCiphertext({encodedText}, {rows})" + go: "decodeCiphertext({encodedText}, {rows})" + dart: "Solution().decodeCiphertext({encodedText}, {rows})" + swift: "Solution().decodeCiphertext({encodedText}, {rows})" + typescript: "decodeCiphertext({encodedText}, {rows})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().decodeCiphertext(encodedText, rows, {result})" + checker: | + class Checker: + def decodeCiphertext(self, encodedText, rows, result): + if not isinstance(result, str) or rows < 1: + return False + cols = len(encodedText) // rows + expected = [] + for c in range(cols): + r = 0 + j = c + while r < rows and j < cols: + expected.append(encodedText[r * cols + j]) + r += 1 + j += 1 + return ''.join(expected).rstrip(' ') == result + +seed: 2075 + +tests: + - name: "example_cipher" + in: + encodedText: "cp i " + rows: 3 + - name: "example_leetcode" + in: + encodedText: "ivle ee l o" + rows: 4 + - name: "example_single_row" + in: + encodedText: "coding" + rows: 1 + - name: "one_character" + in: + encodedText: "a" + rows: 1 + - name: "two_rows_two_chars" + in: + encodedText: "a " + rows: 2 + - name: "two_rows_odd_length" + in: + encodedText: "ac b" + rows: 2 + - name: "two_rows_even_boundary" + in: + encodedText: "ac b" + rows: 2 + - name: "two_rows_five" + in: + encodedText: "ace bd" + rows: 2 + - name: "two_rows_six" + in: + encodedText: "ace bd" + rows: 2 + - name: "two_rows_seven" + in: + encodedText: "aceg bdf" + rows: 2 + - name: "three_rows_eight" + in: + encodedText: "adf be c" + rows: 3 + - name: "three_rows_hello" + in: + encodedText: "hl e " + rows: 3 + - name: "spaces_in_original" + in: + encodedText: "ab " + rows: 2 + - name: "space_between_words" + in: + encodedText: "a d bc" + rows: 2 + - name: "double_space" + in: + encodedText: "a " + rows: 2 + - name: "four_rows_leetcode" + in: + encodedText: "le e " + rows: 4 + - name: "five_rows_transposition" + in: + encodedText: "tnp rs a " + rows: 5 + - name: "three_rows_phrase" + in: + encodedText: "sndih lt p aec" + rows: 3 + - name: "lowercase_two_rows" + in: + encodedText: "lwrae oecs" + rows: 2 + - name: "spaces_matter" + in: + encodedText: "semt psa a c" + rows: 4 + - name: "rows_exceed_text" + in: + encodedText: "ts e " + rows: 7 + - name: "alphabet_three_rows" + in: + encodedText: "adgi beh cf" + rows: 3 + - name: "alphabet_four_rows" + in: + encodedText: "aehj bfi cg d" + rows: 4 + - name: "sentence_five_rows" + in: + encodedText: "tqc huk ei " + rows: 5 + - name: "rows_equal_length" + in: + encodedText: "o " + rows: 6 + - name: "matrix_two_rows" + in: + encodedText: "mti ar" + rows: 2 + - name: "three_rows_short" + in: + encodedText: "eg d " + rows: 3 + - name: "longer_phrase" + in: + encodedText: "letx ore n g" + rows: 4 + - name: "three_word_phrase" + in: + encodedText: "o ohe nt r ewt" + rows: 3 + - name: "decode_phrase" + in: + encodedText: "dcd hs eoeti" + rows: 2 + - name: "single_spaces" + in: + encodedText: "xyz " + rows: 2 + - name: "repeated_letters" + in: + encodedText: "aa a " + rows: 3 + - name: "repeated_words" + in: + encodedText: "acac b b" + rows: 2 + - name: "many_internal_spaces" + in: + encodedText: "a c b" + rows: 3 + - name: "final_phrase" + in: + encodedText: "flxm i a ne a" + rows: 4 + - name: "six_rows_boundary" + in: + encodedText: "rw o " + rows: 6 + - name: "generated_single_row_large" + seed: 101 + in: + encodedText: + gen: "str" + len: 100000 + alphabet: "abc" + rows: 1 + - name: "generated_thousand_rows" + seed: 102 + in: + encodedText: + gen: "str" + len: 100000 + alphabet: "abc " + rows: 1000 + - name: "generated_999_rows" + seed: 104 + in: + encodedText: + gen: "str" + len: 999000 + alphabet: "abc " + rows: 999 + - name: "generated_maximum" + seed: 105 + in: + encodedText: + gen: "str" + len: 1000000 + alphabet: "abc " + rows: 1000 diff --git a/tests/2001-2500/2075. decode-the-slanted-ciphertext/sol.py b/tests/2001-2500/2075. decode-the-slanted-ciphertext/sol.py new file mode 100644 index 00000000..d59ae51e --- /dev/null +++ b/tests/2001-2500/2075. decode-the-slanted-ciphertext/sol.py @@ -0,0 +1,17 @@ +class Solution: + def decodeCiphertext(self, encodedText: str, rows: int) -> str: + if rows == 1: + return encodedText + + n = len(encodedText) + cols = n // rows + res = [] + + for c in range(cols): + r, j = 0, c + while r < rows and j < cols: + res.append(encodedText[r * cols + j]) + r += 1 + j += 1 + + return "".join(res).rstrip() \ No newline at end of file diff --git a/tests/2001-2500/2076. process-restricted-friend-requests/manifest.yaml b/tests/2001-2500/2076. process-restricted-friend-requests/manifest.yaml new file mode 100644 index 00000000..55a7200e --- /dev/null +++ b/tests/2001-2500/2076. process-restricted-friend-requests/manifest.yaml @@ -0,0 +1,639 @@ +entry: + id: 2076 + title: "process-restricted-friend-requests" + params: + n: + type: int + restrictions: + type: array + items: + type: array + items: + type: int + requests: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().friendRequests({n}, {restrictions}, {requests})" + rust: "Solution::friend_requests({n}, {restrictions}, {requests})" + python3: "Solution().friendRequests({n}, {restrictions}, {requests})" + python2: "Solution().friendRequests({n}, {restrictions}, {requests})" + ruby: "friend_requests({n}, {restrictions}, {requests})" + java: "new Solution().friendRequests({n}, {restrictions}, {requests})" + csharp: "new Solution().FriendRequests({n}, {restrictions}, {requests})" + kotlin: "Solution().friendRequests({n}, {restrictions}, {requests})" + go: "friendRequests({n}, {restrictions}, {requests})" + dart: "Solution().friendRequests({n}, {restrictions}, {requests})" + swift: "Solution().friendRequests({n}, {restrictions}, {requests})" + typescript: "friendRequests({n}, {restrictions}, {requests})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 256 + +oracle: + python3: + call: "Checker().friendRequests(n, restrictions, requests, {result})" + checker: | + class Checker: + def friendRequests(self, n, restrictions, requests, result): + parent = list(range(n)) + def find(x): + while parent[x] != x: + parent[x] = parent[parent[x]] + x = parent[x] + return x + expected = [] + for u, v in requests: + ru, rv = find(u), find(v) + ok = ru == rv + if not ok: + for a, b in restrictions: + ra, rb = find(a), find(b) + if (ra == ru and rb == rv) or (ra == rv and rb == ru): + ok = False + break + else: + ok = True + expected.append(ok) + if ok and ru != rv: + parent[ru] = rv + return result == expected + +seed: 20762076 + +tests: + - name: "example-1" + in: + n: 3 + restrictions: + - [0, 1] + requests: + - [0, 2] + - [2, 1] + out: [true, false] + - name: "example-2" + in: + n: 3 + restrictions: + - [0, 1] + requests: + - [1, 2] + - [0, 2] + out: [true, false] + - name: "example-3" + in: + n: 5 + restrictions: + - [0, 1] + - [1, 2] + - [2, 3] + requests: + - [0, 4] + - [1, 2] + - [3, 1] + - [3, 4] + out: [true, false, true, false] + - name: "no-restrictions-chain" + in: + n: 6 + restrictions: [] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [4, 5] + - [0, 5] + out: [true, true, true, true, true] + - name: "single-request-allowed" + in: + n: 2 + restrictions: [] + requests: + - [0, 1] + out: [true] + - name: "single-direct-restriction" + in: + n: 2 + restrictions: + - [0, 1] + requests: + - [0, 1] + out: [false] + - name: "repeated-friends" + in: + n: 4 + restrictions: + - [0, 3] + requests: + - [0, 1] + - [1, 0] + - [0, 1] + - [2, 3] + - [3, 2] + out: [true, true, true, true, true] + - name: "restriction-between-components" + in: + n: 5 + restrictions: + - [0, 4] + requests: + - [0, 1] + - [2, 3] + - [1, 2] + - [3, 4] + out: [true, true, true, false] + - name: "rejected-merge-does-not-change-state" + in: + n: 5 + restrictions: + - [0, 3] + requests: + - [0, 1] + - [2, 3] + - [1, 2] + - [0, 4] + - [4, 3] + out: [true, true, false, true, false] + - name: "multiple-restrictions" + in: + n: 6 + restrictions: + - [0, 2] + - [1, 3] + - [4, 5] + requests: + - [0, 1] + - [2, 3] + - [0, 2] + - [1, 3] + - [4, 0] + - [5, 1] + out: [true, true, false, false, true, false] + - name: "star-blocks-leaves" + in: + n: 7 + restrictions: + - [1, 5] + - [2, 6] + requests: + - [0, 1] + - [0, 2] + - [5, 3] + - [6, 4] + - [3, 4] + - [0, 5] + - [0, 6] + out: [true, true, true, true, true, false, false] + - name: "all-pairs-restricted" + in: + n: 4 + restrictions: + - [0, 1] + - [0, 2] + - [0, 3] + - [1, 2] + - [1, 3] + - [2, 3] + requests: + - [0, 1] + - [2, 3] + - [0, 2] + - [1, 3] + out: [false, false, false, false] + - name: "components-safe-order" + in: + n: 8 + restrictions: + - [0, 7] + - [1, 6] + - [2, 5] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [6, 7] + - [1, 2] + - [3, 4] + - [5, 6] + - [0, 7] + out: [true, true, true, true, true, false, true, false] + - name: "same-component-after-long-chain" + in: + n: 10 + restrictions: + - [0, 9] + - [2, 8] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + - [0, 9] + out: [true, true, true, true, true, true, true, false, true, false] + - name: "isolated-persons" + in: + n: 9 + restrictions: + - [0, 1] + - [3, 4] + requests: + - [2, 5] + - [5, 8] + - [2, 8] + - [0, 3] + - [1, 4] + - [6, 7] + - [0, 4] + out: [true, true, true, true, true, true, false] + - name: "restriction-becomes-indirect" + in: + n: 6 + restrictions: + - [0, 5] + requests: + - [0, 1] + - [2, 3] + - [1, 2] + - [3, 4] + - [4, 5] + - [0, 5] + out: [true, true, true, true, false, false] + - name: "empty-restrictions-many-requests" + in: + n: 10 + restrictions: [] + requests: + - [0, 9] + - [1, 8] + - [2, 7] + - [3, 6] + - [4, 5] + - [0, 1] + - [2, 3] + - [4, 6] + - [7, 8] + - [5, 9] + out: [true, true, true, true, true, true, true, true, true, true] + - name: "duplicate-restrictions" + in: + n: 5 + restrictions: + - [0, 1] + - [1, 0] + - [0, 1] + requests: + - [0, 1] + - [0, 2] + - [2, 1] + - [1, 3] + - [0, 3] + out: [false, true, false, true, false] + - name: "late-cross-component-conflict" + in: + n: 7 + restrictions: + - [0, 6] + - [2, 5] + requests: + - [0, 1] + - [1, 2] + - [3, 4] + - [4, 5] + - [6, 3] + - [0, 6] + - [2, 5] + out: [true, true, true, true, true, false, false] + - name: "two-independent-conflicts" + in: + n: 8 + restrictions: + - [0, 3] + - [4, 7] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [6, 7] + - [1, 2] + - [5, 6] + - [0, 3] + - [4, 7] + out: [true, true, true, true, false, false, false, false] + - name: "n-1000-sparse" + in: + n: 1000 + restrictions: + - [0, 999] + - [100, 900] + - [250, 750] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [100, 101] + - [101, 102] + - [899, 900] + - [0, 999] + - [250, 750] + - [4, 999] + out: [true, true, true, true, true, true, true, false, false, false] + - name: "n-1000-dense-requests" + in: + n: 1000 + restrictions: + - [0, 500] + - [1, 501] + - [2, 502] + - [3, 503] + - [4, 504] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [500, 501] + - [501, 502] + - [502, 503] + - [503, 504] + - [0, 500] + - [4, 504] + out: [true, true, true, true, true, true, true, true, false, false] + - name: "alternating-requests" + in: + n: 6 + restrictions: + - [0, 3] + - [1, 4] + - [2, 5] + requests: + - [0, 1] + - [3, 4] + - [1, 2] + - [4, 5] + - [0, 2] + - [3, 5] + out: [true, true, true, true, true, true] + - name: "merge-restriction-endpoints" + in: + n: 5 + restrictions: + - [0, 4] + requests: + - [0, 1] + - [4, 3] + - [1, 2] + - [2, 3] + - [0, 4] + out: [true, true, true, false, false] + - name: "reverse-chain" + in: + n: 6 + restrictions: + - [0, 5] + requests: + - [5, 4] + - [4, 3] + - [3, 2] + - [2, 1] + - [1, 0] + out: [true, true, true, true, false] + - name: "restriction-unused" + in: + n: 5 + restrictions: + - [0, 4] + - [1, 3] + requests: + - [0, 1] + - [2, 3] + - [2, 4] + - [0, 2] + out: [true, true, true, false] + - name: "same-person-components" + in: + n: 4 + restrictions: + - [0, 2] + requests: + - [0, 1] + - [0, 1] + - [2, 3] + - [2, 3] + - [1, 3] + out: [true, true, true, true, false] + - name: "three-way-restriction-cycle" + in: + n: 6 + restrictions: + - [0, 2] + - [2, 4] + - [4, 0] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [1, 3] + - [3, 5] + - [0, 2] + out: [true, true, true, false, false, false] + - name: "one-restriction-many-bridges" + in: + n: 8 + restrictions: + - [0, 7] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [6, 7] + - [1, 2] + - [3, 4] + - [5, 6] + - [0, 7] + - [0, 6] + out: [true, true, true, true, true, true, false, false, false] + - name: "early-rejection-later-safe" + in: + n: 5 + restrictions: + - [0, 2] + requests: + - [0, 1] + - [1, 2] + - [0, 2] + - [3, 4] + - [0, 3] + out: [true, false, false, true, true] + - name: "all-people-one-component" + in: + n: 7 + restrictions: + - [0, 6] + - [1, 5] + - [2, 4] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [0, 6] + out: [true, true, true, false, true, true, false] + - name: "two-disjoint-groups" + in: + n: 10 + restrictions: + - [0, 4] + - [5, 9] + requests: + - [0, 1] + - [1, 2] + - [2, 3] + - [5, 6] + - [6, 7] + - [7, 8] + - [3, 4] + - [8, 9] + - [0, 5] + out: [true, true, true, true, true, true, false, false, true] + - name: "restriction-symmetric-input" + in: + n: 6 + restrictions: + - [4, 1] + - [3, 0] + requests: + - [1, 2] + - [2, 4] + - [0, 5] + - [5, 3] + - [1, 0] + - [4, 3] + out: [true, false, true, false, true, true] + - name: "bridges-around-restriction" + in: + n: 9 + restrictions: + - [0, 8] + - [2, 6] + requests: + - [0, 1] + - [1, 2] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [0, 8] + - [2, 6] + out: [true, true, true, true, true, true, true, false, false] + - name: "no-op-after-rejection" + in: + n: 4 + restrictions: + - [0, 3] + requests: + - [0, 1] + - [2, 3] + - [1, 2] + - [0, 3] + - [0, 1] + - [2, 3] + out: [true, true, false, false, true, true] + - name: "dense-restrictions-small" + in: + n: 7 + restrictions: + - [0, 1] + - [0, 2] + - [0, 3] + - [1, 4] + - [2, 5] + - [3, 6] + - [4, 5] + - [5, 6] + requests: + - [0, 4] + - [1, 2] + - [3, 5] + - [4, 6] + - [0, 5] + - [1, 6] + out: [true, true, true, true, false, false] + - name: "long-safe-prefix" + in: + n: 12 + restrictions: + - [0, 11] + - [1, 10] + requests: + - [0, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + - [9, 10] + - [10, 11] + - [0, 11] + out: [true, true, true, true, true, true, true, true, true, false, false] + - name: "late-merge-of-singletons" + in: + n: 8 + restrictions: + - [0, 7] + - [2, 6] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [1, 2] + - [3, 4] + - [5, 6] + - [0, 7] + out: [true, true, true, true, true, false, false] + - name: "maximum-index-only" + in: + n: 1000 + restrictions: + - [998, 999] + requests: + - [997, 998] + - [0, 997] + - [0, 999] + - [998, 999] + out: [true, true, false, false] + - name: "alternating-safe-and-blocked" + in: + n: 8 + restrictions: + - [0, 7] + - [1, 6] + - [2, 5] + - [3, 4] + requests: + - [0, 1] + - [2, 3] + - [4, 5] + - [6, 7] + - [1, 2] + - [3, 4] + - [0, 7] + - [1, 6] + out: [true, true, true, true, true, false, false, false] diff --git a/tests/2001-2500/2076. process-restricted-friend-requests/sol.py b/tests/2001-2500/2076. process-restricted-friend-requests/sol.py new file mode 100644 index 00000000..53ecc8a0 --- /dev/null +++ b/tests/2001-2500/2076. process-restricted-friend-requests/sol.py @@ -0,0 +1,32 @@ +class Solution(object): + def friendRequests(self, n, restrictions, requests): + """ + :type n: int + :type restrictions: List[List[int]] + :type requests: List[List[int]] + :rtype: List[bool] + """ + parent = list(range(n)) + + def find(x): + if parent[x] != x: + parent[x] = find(parent[x]) + return parent[x] + + def union(x, y): + root_x, root_y = find(x), find(y) + if root_x == root_y: + return True + + for a, b in restrictions: + ra, rb = find(a), find(b) + if (root_x == ra and root_y == rb) or (root_x == rb and root_y == ra): + return False + + parent[root_x] = root_y + return True + + results = [] + for x, y in requests: + results.append(union(x, y)) + return results \ No newline at end of file diff --git a/tests/2001-2500/2078. two-furthest-houses-with-different-colors/manifest.yaml b/tests/2001-2500/2078. two-furthest-houses-with-different-colors/manifest.yaml new file mode 100644 index 00000000..c5b3edda --- /dev/null +++ b/tests/2001-2500/2078. two-furthest-houses-with-different-colors/manifest.yaml @@ -0,0 +1,248 @@ +entry: + id: 2078 + title: "two-furthest-houses-with-different-colors" + params: + colors: + type: array + items: + type: int + call: + cpp: "Solution().maxDistance({colors})" + rust: "Solution::max_distance({colors})" + python3: "Solution().maxDistance({colors})" + python2: "Solution().maxDistance({colors})" + ruby: "max_distance({colors})" + java: "new Solution().maxDistance({colors})" + csharp: "new Solution().MaxDistance({colors})" + kotlin: "Solution().maxDistance({colors})" + go: "maxDistance({colors})" + dart: "Solution().maxDistance({colors})" + swift: "Solution().maxDistance({colors})" + typescript: "maxDistance({colors})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().maxDistance(colors, {result})" + checker: | + class Checker: + def maxDistance(self, colors, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + best = 0 + for i in range(len(colors)): + for j in range(i + 1, len(colors)): + if colors[i] != colors[j]: + best = max(best, j - i) + return result == best + +seed: 20782026 + +tests: + - name: "example_1" + in: + colors: [1, 1, 1, 6, 1, 1, 1] + out: 3 + - name: "example_2" + in: + colors: [1, 8, 3, 8, 3] + out: 4 + - name: "example_3" + in: + colors: [0, 1] + out: 1 + - name: "minimum_two_equal_not_allowed_but_boundary" + in: + colors: [0, 100] + out: 1 + - name: "different_colors_adjacent_middle" + in: + colors: [7, 7, 3, 7, 7] + out: 2 + - name: "different_endpoints" + in: + colors: [4, 4, 4, 4, 9] + out: 4 + - name: "same_endpoints_middle_difference" + in: + colors: [5, 5, 2, 5, 5] + out: 2 + - name: "alternating_two_colors" + in: + colors: [1, 2, 1, 2, 1, 2, 1, 2] + out: 7 + - name: "constant_run_then_other_run" + in: + colors: [3, 3, 3, 3, 8, 8, 8] + out: 6 + - name: "single_outlier_near_left" + in: + colors: [9, 2, 9, 9, 9, 9, 9, 9] + out: 6 + - name: "single_outlier_near_right" + in: + colors: [9, 9, 9, 9, 9, 9, 2, 9] + out: 6 + - name: "unique_center" + in: + colors: [6, 6, 6, 1, 6, 6, 6, 6, 6] + out: 5 + - name: "three_colors_endpoints_same" + in: + colors: [1, 2, 3, 2, 1] + out: 3 + - name: "endpoints_same_farther_inner" + in: + colors: [4, 4, 4, 8, 4, 4, 4, 4, 4] + out: 5 + - name: "all_distinct_small" + in: + colors: [0, 1, 2, 3, 4, 5] + out: 5 + - name: "large_color_values" + in: + colors: [100, 100, 100, 0, 100, 100, 100, 100] + out: 4 + - name: "two_blocks_equal_length" + in: + colors: [11, 11, 11, 11, 22, 22, 22, 22] + out: 7 + - name: "edge_difference_at_index_one" + in: + colors: [5, 8, 5, 5, 5, 5, 5] + out: 5 + - name: "edge_difference_at_penultimate" + in: + colors: [5, 5, 5, 5, 5, 8, 5] + out: 5 + - name: "three_house_pattern" + in: + colors: [2, 2, 9] + out: 2 + - name: "repeated_inner_colors" + in: + colors: [1, 3, 3, 3, 2, 3, 3, 1] + out: 6 + - name: "endpoint_left_only_difference" + in: + colors: [1, 2, 2, 2, 2, 2, 2, 2, 2, 2] + out: 9 + - name: "endpoint_right_only_difference" + in: + colors: [2, 2, 2, 2, 2, 2, 2, 2, 2, 1] + out: 9 + - name: "symmetric_four_colors" + in: + colors: [1, 2, 3, 2, 3, 2, 1] + out: 5 + - name: "long_prefix_and_suffix" + in: + colors: [7, 7, 7, 7, 7, 7, 7, 4, 4, 4, 4, 4] + out: 11 + - name: "max_length_all_same_except_last" + in: + colors: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100] + out: 49 + - name: "max_length_all_same_except_first" + in: + colors: [100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + out: 49 + - name: "max_length_different_endpoints" + in: + colors: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100] + out: 49 + - name: "mixed_repeated_values" + in: + colors: [8, 6, 8, 6, 6, 8, 6, 8, 8, 6] + out: 9 + - name: "late_new_color" + in: + colors: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3] + out: 10 + - name: "early_new_color" + in: + colors: [4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] + out: 11 + - name: "generated_distinct_small" + seed: 101 + in: + colors: + gen: "array" + len: + gen: "int" + min: 2 + max: 12 + of: + gen: "int" + min: 0 + max: 100 + distinct: true + sorted: false + elemType: "int" + - name: "generated_distinct_medium" + seed: 202 + in: + colors: + gen: "array" + len: + gen: "int" + min: 20 + max: 45 + of: + gen: "int" + min: 0 + max: 100 + distinct: true + sorted: false + elemType: "int" + - name: "generated_distinct_boundary" + seed: 303 + in: + colors: + gen: "array" + len: 100 + of: + gen: "int" + min: 0 + max: 100 + distinct: true + sorted: false + elemType: "int" + - name: "generated_distinct_long" + seed: 404 + in: + colors: + gen: "array" + len: + gen: "int" + min: 70 + max: 99 + of: + gen: "int" + min: 0 + max: 100 + distinct: true + sorted: false + elemType: "int" + - name: "generated_distinct_high_values" + seed: 505 + in: + colors: + gen: "array" + len: + gen: "int" + min: 2 + max: 30 + of: + gen: "int" + min: 71 + max: 100 + distinct: true + sorted: false + elemType: "int" diff --git a/tests/2001-2500/2078. two-furthest-houses-with-different-colors/sol.py b/tests/2001-2500/2078. two-furthest-houses-with-different-colors/sol.py new file mode 100644 index 00000000..d81ed376 --- /dev/null +++ b/tests/2001-2500/2078. two-furthest-houses-with-different-colors/sol.py @@ -0,0 +1,9 @@ +class Solution: + def maxDistance(self, colors: List[int]) -> int: + n=len(colors) + c0, cN=colors[0], colors[-1] + lMax, rMax=0, 0 + for i, c in enumerate(colors): + if c0!=c: lMax=max(lMax, i) + if cN!=c: rMax=max(rMax, n-1-i) + return max(lMax, rMax) \ No newline at end of file diff --git a/tests/2001-2500/2079. watering-plants/manifest.yaml b/tests/2001-2500/2079. watering-plants/manifest.yaml new file mode 100644 index 00000000..3c38d253 --- /dev/null +++ b/tests/2001-2500/2079. watering-plants/manifest.yaml @@ -0,0 +1,260 @@ +entry: + id: 2079 + title: "watering-plants" + params: + plants: + type: array + items: + type: int + capacity: + type: int + call: + cpp: "Solution().wateringPlants({plants}, {capacity})" + rust: "Solution::watering_plants({plants}, {capacity})" + python3: "Solution().wateringPlants({plants}, {capacity})" + python2: "Solution().wateringPlants({plants}, {capacity})" + ruby: "watering_plants({plants}, {capacity})" + java: "new Solution().wateringPlants({plants}, {capacity})" + csharp: "new Solution().WateringPlants({plants}, {capacity})" + kotlin: "Solution().wateringPlants({plants}, {capacity})" + go: "wateringPlants({plants}, {capacity})" + dart: "Solution().wateringPlants({plants}, {capacity})" + swift: "Solution().wateringPlants({plants}, {capacity})" + typescript: "wateringPlants({plants}, {capacity})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().wateringPlants(plants, capacity, {result})" + checker: | + class Checker: + def wateringPlants(self, plants, capacity, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + water = capacity + steps = 0 + for i, need in enumerate(plants): + if need > water: + steps += 2 * i + water = capacity + steps += 1 + water -= need + return result == steps + +seed: 2079 + +tests: + - name: "example_1" + in: + plants: [2, 2, 3, 3] + capacity: 5 + out: 14 + - name: "example_2" + in: + plants: [1, 1, 1, 4, 2, 3] + capacity: 4 + out: 30 + - name: "example_3" + in: + plants: [7, 7, 7, 7, 7, 7, 7] + capacity: 8 + out: 49 + - name: "single_exact_capacity" + in: + plants: [5] + capacity: 5 + out: 1 + - name: "minimum_capacity_repeated" + in: + plants: [1, 1, 1] + capacity: 1 + out: 9 + - name: "one_refill_at_end" + in: + plants: [1, 2, 3] + capacity: 3 + out: 7 + - name: "refill_after_partial_run" + in: + plants: [3, 1, 1, 3] + capacity: 3 + out: 12 + - name: "alternating_needs" + in: + plants: [2, 1, 2, 1, 2] + capacity: 3 + out: 17 + - name: "two_full_capacity_plants" + in: + plants: [4, 4] + capacity: 4 + out: 4 + - name: "large_plant_after_small" + in: + plants: [1, 4, 1, 4] + capacity: 4 + out: 16 + - name: "exact_fit_sequence" + in: + plants: [2, 3, 1, 2] + capacity: 5 + out: 8 + - name: "full_then_small" + in: + plants: [6, 1, 1, 1] + capacity: 6 + out: 6 + - name: "near_capacity_pairs" + in: + plants: [1, 5, 2, 5] + capacity: 5 + out: 16 + - name: "capacity_ten_exact" + in: + plants: [10, 10, 10] + capacity: 10 + out: 9 + - name: "alternating_ten" + in: + plants: [1, 9, 1, 9, 1] + capacity: 10 + out: 17 + - name: "four_equal_near_capacity" + in: + plants: [3, 3, 3, 3] + capacity: 4 + out: 16 + - name: "five_pairs" + in: + plants: [2, 2, 2, 2, 2] + capacity: 4 + out: 17 + - name: "large_small_alternation" + in: + plants: [7, 1, 7, 1] + capacity: 7 + out: 16 + - name: "large_middle_plant" + in: + plants: [1, 1, 8, 1, 1] + capacity: 8 + out: 15 + - name: "long_tail_after_full" + in: + plants: [5, 1, 1, 1, 1, 5] + capacity: 5 + out: 18 + - name: "capacity_four_mixed" + in: + plants: [2, 4, 2, 4] + capacity: 4 + out: 16 + - name: "small_repeated_pattern" + in: + plants: [1, 2, 1, 2, 1, 2] + capacity: 3 + out: 18 + - name: "large_edges" + in: + plants: [9, 1, 1, 9] + capacity: 9 + out: 12 + - name: "capacity_two_ones" + in: + plants: [1, 1, 1, 1, 1] + capacity: 2 + out: 17 + - name: "capacity_two_mixed" + in: + plants: [2, 1, 2, 1, 2] + capacity: 2 + out: 25 + - name: "maximum_single_value" + in: + plants: [1000000] + capacity: 1000000 + out: 1 + - name: "maximum_then_small" + in: + plants: [1000000, 1] + capacity: 1000000 + out: 4 + - name: "small_maximum_small" + in: + plants: [1, 1000000, 1] + capacity: 1000000 + out: 9 + - name: "near_maximum_equal" + in: + plants: [999999, 999999] + capacity: 999999 + out: 4 + - name: "capacity_six_pattern" + in: + plants: [4, 2, 4, 2, 4] + capacity: 6 + out: 17 + - name: "capacity_five_varied" + in: + plants: [1, 3, 5, 1, 3] + capacity: 5 + out: 15 + - name: "single_plant_minimum" + in: + plants: [1] + capacity: 1 + out: 1 + - name: "all_small_capacity_large" + in: + plants: [1, 1, 1, 1, 1, 1, 1, 1] + capacity: 1000000000 + out: 8 + - name: "mixed_exact_capacity" + in: + plants: [2, 2, 2, 2, 2, 2] + capacity: 6 + out: 12 + - name: "maximum_capacity_mixed" + in: + plants: [1000000, 1, 1, 999998] + capacity: 1000000 + out: 6 + - name: "stress_all_minimum" + in: + plants: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 1 + capacity: 1 + out: 1000000 + - name: "stress_full_capacity" + in: + plants: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 1 + capacity: 1000000000 + out: 1000 + - name: "stress_maximum_plants" + in: + plants: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1000000 + max: 1000000 + capacity: 1000000 + out: 1000000 diff --git a/tests/2001-2500/2079. watering-plants/sol.py b/tests/2001-2500/2079. watering-plants/sol.py new file mode 100644 index 00000000..94ae6a03 --- /dev/null +++ b/tests/2001-2500/2079. watering-plants/sol.py @@ -0,0 +1,14 @@ +class Solution: + def wateringPlants(self, plants: List[int], capacity: int) -> int: + res=0 + c=capacity + for i in range(len(plants)): + steps=0 + if plants[i]<=capacity: + steps=1 + capacity-=plants[i] + elif plants[i]>capacity: + capacity=c-plants[i] + steps+=(2*i)+1 + res+=steps + return res \ No newline at end of file diff --git a/tests/2001-2500/2080. range-frequency-queries/sol.py b/tests/2001-2500/2080. range-frequency-queries/sol.py new file mode 100644 index 00000000..5943e12b --- /dev/null +++ b/tests/2001-2500/2080. range-frequency-queries/sol.py @@ -0,0 +1,32 @@ +class Solution: + class RangeFreqQuery(object): + def __init__(self, arr): + """ + :type arr: List[int] + """ + self.pos = {} + for i, num in enumerate(arr): + if num not in self.pos: + self.pos[num] = [] + self.pos[num].append(i) + + def query(self, left, right, value): + """ + :type left: int + :type right: int + :type value: int + :rtype: int + """ + if value not in self.pos: + return 0 + + indices = self.pos[value] + + l = bisect.bisect_left(indices, left) + r = bisect.bisect_right(indices, right) + + return r - l + + # Your RangeFreqQuery object will be instantiated and called as such: + # obj = RangeFreqQuery(arr) + # param_1 = obj.query(left,right,value) diff --git a/tests/2001-2500/2081. sum-of-k-mirror-numbers/manifest.yaml b/tests/2001-2500/2081. sum-of-k-mirror-numbers/manifest.yaml new file mode 100644 index 00000000..f7190872 --- /dev/null +++ b/tests/2001-2500/2081. sum-of-k-mirror-numbers/manifest.yaml @@ -0,0 +1,304 @@ +entry: + id: 2081 + title: "sum-of-k-mirror-numbers" + params: + k: + type: int + n: + type: int + call: + cpp: "Solution().kMirror({k}, {n})" + rust: "Solution::k_mirror({k}, {n})" + python3: "Solution().kMirror({k}, {n})" + python2: "Solution().kMirror({k}, {n})" + ruby: "k_mirror({k}, {n})" + java: "new Solution().kMirror({k}, {n})" + csharp: "new Solution().KMirror({k}, {n})" + kotlin: "Solution().kMirror({k}, {n})" + go: "kMirror({k}, {n})" + dart: "Solution().kMirror({k}, {n})" + swift: "Solution().kMirror({k}, {n})" + typescript: "kMirror({k}, {n})" + +judge: + type: "exact" + +limits: + time_ms: 5000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().kMirror(k, n, {result})" + checker: | + class Checker: + def kMirror(self, k, n, result): + def make_pal(prefix, odd): + x = prefix // 10 if odd else prefix + value = prefix + while x: + value = value * 10 + x % 10 + x //= 10 + return value + def base_pal(x): + d = [] + while x: + d.append(x % k) + x //= k + return d == d[::-1] + total = 0 + remaining = n + length = 1 + while remaining: + for prefix in range(length, length * 10): + value = make_pal(prefix, True) + if base_pal(value): + total += value + remaining -= 1 + if not remaining: + break + if not remaining: + break + for prefix in range(length, length * 10): + value = make_pal(prefix, False) + if base_pal(value): + total += value + remaining -= 1 + if not remaining: + break + length *= 10 + return result == total + +seed: 2081 + +tests: + - name: "example_k2_n5" + in: + k: 2 + n: 5 + out: 25 + - name: "example_k3_n7" + in: + k: 3 + n: 7 + out: 499 + - name: "example_k7_n17" + in: + k: 7 + n: 17 + out: 20379000 + - name: "base2_first" + in: + k: 2 + n: 1 + out: 1 + - name: "base2_ten" + in: + k: 2 + n: 10 + out: 1772 + - name: "base2_twenty" + in: + k: 2 + n: 20 + out: 2630758 + - name: "base2_max_n" + in: + k: 2 + n: 30 + out: 2609044274 + - name: "base3_first" + in: + k: 3 + n: 1 + out: 1 + - name: "base3_ten" + in: + k: 3 + n: 10 + out: 1881 + - name: "base3_twenty" + in: + k: 3 + n: 20 + out: 2863752 + - name: "base3_max_n" + in: + k: 3 + n: 30 + out: 155059889 + - name: "base4_first" + in: + k: 4 + n: 1 + out: 1 + - name: "base4_five" + in: + k: 4 + n: 5 + out: 66 + - name: "base4_ten" + in: + k: 4 + n: 10 + out: 3224 + - name: "base4_twenty" + in: + k: 4 + n: 20 + out: 12448815 + - name: "base4_max_n" + in: + k: 4 + n: 30 + out: 53393239260 + - name: "base5_first" + in: + k: 5 + n: 1 + out: 1 + - name: "base5_ten" + in: + k: 5 + n: 10 + out: 1940 + - name: "base5_twenty" + in: + k: 5 + n: 20 + out: 1000828708 + - name: "base5_max_n" + in: + k: 5 + n: 30 + out: 43401017264 + - name: "base6_first" + in: + k: 6 + n: 1 + out: 1 + - name: "base6_five" + in: + k: 6 + n: 5 + out: 15 + - name: "base6_ten" + in: + k: 6 + n: 10 + out: 520 + - name: "base6_twenty" + in: + k: 6 + n: 20 + out: 156389 + - name: "base6_max_n" + in: + k: 6 + n: 30 + out: 28888231 + - name: "base7_first" + in: + k: 7 + n: 1 + out: 1 + - name: "base7_twenty" + in: + k: 7 + n: 20 + out: 321578997 + - name: "base7_max_n" + in: + k: 7 + n: 30 + out: 241030621167 + - name: "base8_first" + in: + k: 8 + n: 1 + out: 1 + - name: "base8_ten" + in: + k: 8 + n: 10 + out: 450 + - name: "base8_twenty" + in: + k: 8 + n: 20 + out: 94182 + - name: "base8_max_n" + in: + k: 8 + n: 30 + out: 66619574 + - name: "base9_ten" + in: + k: 9 + n: 10 + out: 509 + - name: "base9_twenty" + in: + k: 9 + n: 20 + out: 156242 + - name: "base9_max_n" + in: + k: 9 + n: 30 + out: 18627530 + - name: "generated_mid_base" + seed: 101 + in: + k: + gen: "int" + min: 2 + max: 9 + n: + gen: "int" + min: 8 + max: 18 + - name: "generated_small_base" + seed: 202 + in: + k: + gen: "int" + min: 2 + max: 4 + n: + gen: "int" + min: 1 + max: 6 + - name: "generated_large_n" + seed: 303 + in: + k: + gen: "int" + min: 5 + max: 9 + n: + gen: "int" + min: 25 + max: 30 + - name: "generated_boundary_base" + seed: 404 + in: + k: + gen: "int" + min: 8 + max: 9 + n: + gen: "int" + min: 2 + max: 12 + - name: "generated_full_range" + seed: 505 + in: + k: + gen: "int" + min: 2 + max: 9 + n: + gen: "int" + min: 19 + max: 30 diff --git a/tests/2001-2500/2081. sum-of-k-mirror-numbers/sol.py b/tests/2001-2500/2081. sum-of-k-mirror-numbers/sol.py new file mode 100644 index 00000000..23e31b87 --- /dev/null +++ b/tests/2001-2500/2081. sum-of-k-mirror-numbers/sol.py @@ -0,0 +1,37 @@ +class Solution: + def createPalindrome(self, num: int, odd: bool) -> int: + x = num + if odd: + x //= 10 + while x > 0: + num = num * 10 + x % 10 + x //= 10 + return num + + def isPalindrome(self, num: int, base: int) -> bool: + digits = [] + while num > 0: + digits.append(num % base) + num //= base + return digits == digits[::-1] + + def kMirror(self, k: int, n: int) -> int: + total = 0 + length = 1 + while n > 0: + for i in range(length, length * 10): + if n <= 0: + break + p = self.createPalindrome(i, True) + if self.isPalindrome(p, k): + total += p + n -= 1 + for i in range(length, length * 10): + if n <= 0: + break + p = self.createPalindrome(i, False) + if self.isPalindrome(p, k): + total += p + n -= 1 + length *= 10 + return total \ No newline at end of file diff --git a/tests/2001-2500/2085. count-common-words-with-one-occurrence/manifest.yaml b/tests/2001-2500/2085. count-common-words-with-one-occurrence/manifest.yaml new file mode 100644 index 00000000..c1fe603a --- /dev/null +++ b/tests/2001-2500/2085. count-common-words-with-one-occurrence/manifest.yaml @@ -0,0 +1,330 @@ +entry: + id: 2085 + title: "count-common-words-with-one-occurrence" + params: + words1: + type: array + items: + type: string + words2: + type: array + items: + type: string + call: + cpp: "Solution().countWords({words1}, {words2})" + rust: "Solution::count_words({words1}, {words2})" + python3: "Solution().countWords({words1}, {words2})" + python2: "Solution().countWords({words1}, {words2})" + ruby: "count_words({words1}, {words2})" + java: "new Solution().countWords({words1}, {words2})" + csharp: "new Solution().CountWords({words1}, {words2})" + kotlin: "Solution().countWords({words1}, {words2})" + go: "countWords({words1}, {words2})" + dart: "Solution().countWords({words1}, {words2})" + swift: "Solution().countWords({words1}, {words2})" + typescript: "countWords({words1}, {words2})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().countWords(words1, words2, {result})" + checker: | + class Checker: + def countWords(self, words1, words2, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + from collections import Counter + expected = sum(1 for word, count in Counter(words1).items() + if count == 1 and Counter(words2)[word] == 1) + return result == expected + +seed: 2085001 + +tests: + - name: "example_1" + in: + words1: ["leetcode", "is", "amazing", "as", "is"] + words2: ["amazing", "leetcode", "is"] + out: 2 + - name: "example_2_disjoint" + in: + words1: ["b", "bb", "bbb"] + words2: ["a", "aa", "aaa"] + out: 0 + - name: "example_3_duplicate_other_side" + in: + words1: ["a", "ab"] + words2: ["a", "a", "a", "ab"] + out: 1 + - name: "single_equal" + in: + words1: ["a"] + words2: ["a"] + out: 1 + - name: "single_different" + in: + words1: ["a"] + words2: ["b"] + out: 0 + - name: "all_duplicates_both" + in: + words1: ["x", "x", "x"] + words2: ["x", "x"] + out: 0 + - name: "duplicate_only_words1" + in: + words1: ["x", "x", "y"] + words2: ["x", "y"] + out: 1 + - name: "duplicate_only_words2" + in: + words1: ["x", "y"] + words2: ["x", "x", "y"] + out: 1 + - name: "several_singletons" + in: + words1: ["a", "b", "c", "d"] + words2: ["d", "c", "b", "a"] + out: 4 + - name: "shared_with_extras" + in: + words1: ["a", "b", "c", "z"] + words2: ["a", "b", "c", "q"] + out: 3 + - name: "repeated_shared_excluded" + in: + words1: ["a", "a", "b", "c", "c"] + words2: ["a", "b", "b", "c"] + out: 0 + - name: "case_is_lowercase_distinct" + in: + words1: ["aa", "ab", "ac"] + words2: ["aa", "ab", "ad"] + out: 2 + - name: "length_one_words" + in: + words1: ["a", "b", "a", "c", "d"] + words2: ["b", "c", "d", "e"] + out: 3 + - name: "length_thirty_equal" + in: + words1: ["abcdefghijklmnopqrstuvwxyzabcd"] + words2: ["abcdefghijklmnopqrstuvwxyzabcd"] + out: 1 + - name: "length_thirty_nonmatching" + in: + words1: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + words2: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbba"] + out: 0 + - name: "same_word_many_unique" + in: + words1: ["one", "two", "three", "four", "five", "six", "seven"] + words2: ["zero", "one", "three", "five", "seven", "eight"] + out: 4 + - name: "intersection_empty" + in: + words1: ["red", "green", "blue"] + words2: ["cyan", "magenta", "yellow", "black"] + out: 0 + - name: "one_side_has_all_duplicates" + in: + words1: ["a", "b", "c"] + words2: ["a", "a", "b", "b", "c", "c"] + out: 0 + - name: "duplicate_frequency_three" + in: + words1: ["a", "a", "a", "b", "c"] + words2: ["a", "b", "c", "c", "c"] + out: 1 + - name: "unique_after_duplicate_noise" + in: + words1: ["noise", "noise", "keep1", "keep2", "other"] + words2: ["noise", "keep1", "keep2", "other", "other"] + out: 2 + - name: "repeated_prefix_words" + in: + words1: ["a", "aa", "aaa", "aaaa"] + words2: ["a", "aa", "aaa", "aaaa"] + out: 4 + - name: "repeated_suffix_words" + in: + words1: ["ba", "cba", "dcba", "edcba", "ba"] + words2: ["ba", "cba", "dcba", "edcba"] + out: 3 + - name: "ordering_irrelevant" + in: + words1: ["delta", "alpha", "charlie", "bravo"] + words2: ["bravo", "charlie", "alpha", "delta"] + out: 4 + - name: "empty_result_from_mixed_counts" + in: + words1: ["a", "b", "b", "c", "d", "d"] + words2: ["a", "a", "b", "c", "c", "d"] + out: 0 + - name: "two_singletons_among_duplicates" + in: + words1: ["a", "a", "b", "c", "c", "d"] + words2: ["a", "b", "b", "c", "d", "d"] + out: 0 + - name: "long_unique_vocab" + in: + words1: ["alphaalphaalpha", "betabetabeta", "gammagammagamma", "delta"] + words2: ["delta", "gammagammagamma", "epsilon", "betabetabeta"] + out: 3 + - name: "unicode_like_not_allowed_but_letters" + in: + words1: ["abcdefghijklmnopqrstuvwx", "yzabcdefghijklmnopqrstuv"] + words2: ["abcdefghijklmnopqrstuvwx", "yzabcdefghijklmnopqrstuv"] + out: 2 + - name: "ten_singletons" + in: + words1: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] + words2: ["j", "i", "h", "g", "f", "e", "d", "c", "b", "a"] + out: 10 + - name: "ten_with_five_duplicates" + in: + words1: ["a", "a", "b", "b", "c", "c", "d", "e", "f", "g"] + words2: ["a", "b", "c", "d", "e", "f", "f", "g", "g", "h"] + out: 2 + - name: "small_alphabet_collisions" + in: + words1: ["aa", "ab", "ac", "aa", "ba", "bb"] + words2: ["aa", "ab", "ac", "ba", "bb", "bb"] + out: 3 + - name: "all_words_same_singleton" + in: + words1: ["solo"] + words2: ["solo"] + out: 1 + - name: "all_words_same_many" + in: + words1: ["same", "same", "same", "same"] + words2: ["same", "same", "same", "same"] + out: 0 + - name: "generated_small" + seed: 208501 + in: + words1: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 6 + alphabet: "abcd" + words2: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 6 + alphabet: "abcd" + - name: "generated_medium" + seed: 208502 + in: + words1: + gen: "array" + len: + gen: "int" + min: 100 + max: 250 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 12 + alphabet: "abcdef" + words2: + gen: "array" + len: + gen: "int" + min: 100 + max: 250 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 12 + alphabet: "abcdef" + - name: "generated_maximum_short_vocab" + seed: 208503 + in: + words1: + gen: "array" + len: 1000 + of: + gen: "str" + len: 3 + alphabet: "abcdefgh" + words2: + gen: "array" + len: 1000 + of: + gen: "str" + len: 3 + alphabet: "abcdefgh" + - name: "generated_maximum_long_words" + seed: 208504 + in: + words1: + gen: "array" + len: 1000 + of: + gen: "str" + len: 30 + alphabet: "abcdefghijkl" + words2: + gen: "array" + len: 1000 + of: + gen: "str" + len: 30 + alphabet: "abcdefghijkl" + - name: "generated_boundary_lengths" + seed: 208505 + in: + words1: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 30 + alphabet: "az" + words2: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 30 + alphabet: "az" diff --git a/tests/2001-2500/2085. count-common-words-with-one-occurrence/sol.py b/tests/2001-2500/2085. count-common-words-with-one-occurrence/sol.py new file mode 100644 index 00000000..e7ee8ed3 --- /dev/null +++ b/tests/2001-2500/2085. count-common-words-with-one-occurrence/sol.py @@ -0,0 +1,8 @@ +class Solution(object): + def countWords(self, words1, words2): + c=0 + for i in words1: + if words1.count(i)==1: + if words2.count(i)==1: + c+=1 + return c \ No newline at end of file diff --git a/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/manifest.yaml b/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/manifest.yaml new file mode 100644 index 00000000..6604cb70 --- /dev/null +++ b/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/manifest.yaml @@ -0,0 +1,224 @@ +entry: + id: 2086 + title: "minimum-number-of-food-buckets-to-feed-the-hamsters" + params: + hamsters: + type: string + call: + cpp: "Solution().minimumBuckets({hamsters})" + rust: "Solution::minimum_buckets({hamsters})" + python3: "Solution().minimumBuckets({hamsters})" + python2: "Solution().minimumBuckets({hamsters})" + ruby: "minimum_buckets({hamsters})" + java: "new Solution().minimumBuckets({hamsters})" + csharp: "new Solution().MinimumBuckets({hamsters})" + kotlin: "Solution().minimumBuckets({hamsters})" + go: "minimumBuckets({hamsters})" + dart: "Solution().minimumBuckets({hamsters})" + swift: "Solution().minimumBuckets({hamsters})" + typescript: "minimumBuckets({hamsters})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumBuckets(hamsters, {result})" + checker: | + class Checker: + def minimumBuckets(self, hamsters, result): + buckets = 0 + s = list(hamsters) + for i, ch in enumerate(s): + if ch != "H": + continue + if i > 0 and s[i - 1] == "B": + continue + if i + 1 < len(s) and s[i + 1] == ".": + s[i + 1] = "B" + buckets += 1 + elif i > 0 and s[i - 1] == ".": + s[i - 1] = "B" + buckets += 1 + else: + return result == -1 + return result == buckets + +seed: 2086 + +tests: + - name: "example_1" + in: + hamsters: "H..H" + out: 2 + - name: "example_2" + in: + hamsters: ".H.H." + out: 1 + - name: "example_3" + in: + hamsters: ".HHH." + out: -1 + - name: "single_empty" + in: + hamsters: "." + out: 0 + - name: "single_hamster" + in: + hamsters: "H" + out: -1 + - name: "two_empty" + in: + hamsters: ".." + out: 0 + - name: "two_hamsters" + in: + hamsters: "HH" + out: -1 + - name: "edge_hamster_left" + in: + hamsters: "H." + out: 1 + - name: "edge_hamster_right" + in: + hamsters: ".H" + out: 1 + - name: "three_empty" + in: + hamsters: "..." + out: 0 + - name: "separated_pair" + in: + hamsters: "H.H" + out: 1 + - name: "two_spacer_pair" + in: + hamsters: "H..H" + out: 2 + - name: "three_spacer_pair" + in: + hamsters: "H...H" + out: 2 + - name: "leading_trailing_empty" + in: + hamsters: ".H." + out: 1 + - name: "alternating_start_h" + in: + hamsters: "H.H.H" + out: 2 + - name: "alternating_start_empty" + in: + hamsters: ".H.H.H." + out: 2 + - name: "four_hamster_block" + in: + hamsters: ".H.H.H.H." + out: 2 + - name: "blocked_pair_middle" + in: + hamsters: ".HH." + out: 2 + - name: "blocked_pair_left" + in: + hamsters: "HH." + out: -1 + - name: "blocked_pair_right" + in: + hamsters: ".HH" + out: -1 + - name: "triple_block" + in: + hamsters: "H.HHH." + out: -1 + - name: "four_empty_between" + in: + hamsters: "H....H" + out: 2 + - name: "two_groups" + in: + hamsters: "H.H..H.H" + out: 2 + - name: "dense_feasible" + in: + hamsters: ".H.HH.H." + out: 2 + - name: "long_empty_edges" + in: + hamsters: ".....H....." + out: 1 + - name: "long_single_gap" + in: + hamsters: "HHHH" + out: -1 + - name: "end_pair_with_gap" + in: + hamsters: "..H.H" + out: 1 + - name: "interior_single" + in: + hamsters: "HH.HH" + out: -1 + - name: "many_reusable_gaps" + in: + hamsters: "H.H.H.H.H.H.H" + out: 4 + - name: "mixed_runs" + in: + hamsters: "..H..HH..H." + out: 4 + - name: "large_static_pattern" + in: + hamsters: "H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H" + out: 10 + - name: "generated_short" + seed: 101 + in: + hamsters: + gen: "str" + len: + gen: "int" + min: 1 + max: 40 + alphabet: "H." + - name: "generated_medium" + seed: 102 + in: + hamsters: + gen: "str" + len: + gen: "int" + min: 41 + max: 500 + alphabet: "H." + - name: "generated_sparse" + seed: 103 + in: + hamsters: + gen: "str" + len: + gen: "int" + min: 1000 + max: 3000 + alphabet: "H." + - name: "generated_large" + seed: 104 + in: + hamsters: + gen: "str" + len: + gen: "int" + min: 50000 + max: 60000 + alphabet: "H." + - name: "generated_maximum" + seed: 105 + in: + hamsters: + gen: "str" + len: 100000 + alphabet: "H." diff --git a/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/sol.py b/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/sol.py new file mode 100644 index 00000000..4817b70c --- /dev/null +++ b/tests/2001-2500/2086. minimum-number-of-food-buckets-to-feed-the-hamsters/sol.py @@ -0,0 +1,11 @@ +class Solution(object): + def minimumBuckets(self, hamsters): + """ + :type hamsters: str + :rtype: int + """ + n = len(hamsters) + start = 0 + if hamsters == "" or hamsters[:2] == "HH" or hamsters[n-2:] == "HH" or "HHH" in hamsters or hamsters == "H": + return -1 + return hamsters.count("H") - hamsters.count("H.H") \ No newline at end of file diff --git a/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/manifest.yaml b/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/manifest.yaml new file mode 100644 index 00000000..a48437de --- /dev/null +++ b/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/manifest.yaml @@ -0,0 +1,345 @@ +entry: + id: 2087 + title: "minimum-cost-homecoming-of-a-robot-in-a-grid" + params: + startPos: + type: array + items: + type: int + homePos: + type: array + items: + type: int + rowCosts: + type: array + items: + type: int + colCosts: + type: array + items: + type: int + call: + cpp: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + rust: "Solution::min_cost({startPos}, {homePos}, {rowCosts}, {colCosts})" + python3: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + python2: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + ruby: "min_cost({startPos}, {homePos}, {rowCosts}, {colCosts})" + java: "new Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + csharp: "new Solution().MinCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + kotlin: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + go: "minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + dart: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + swift: "Solution().minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + typescript: "minCost({startPos}, {homePos}, {rowCosts}, {colCosts})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().minCost(startPos, homePos, rowCosts, colCosts, {result})" + checker: | + class Checker: + def minCost(self, startPos, homePos, rowCosts, colCosts, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + sr, sc = startPos + hr, hc = homePos + expected = sum(rowCosts[min(sr, hr) + 1:max(sr, hr) + 1]) if sr < hr else sum(rowCosts[hr:sr]) + expected += sum(colCosts[min(sc, hc) + 1:max(sc, hc) + 1]) if sc < hc else sum(colCosts[hc:sc]) + return result == expected + +seed: 2087 + +tests: + - name: "example_down_and_right" + in: + startPos: [1, 0] + homePos: [2, 3] + rowCosts: [5, 4, 3] + colCosts: [8, 2, 6, 7] + out: 18 + - name: "example_same_cell" + in: + startPos: [0, 0] + homePos: [0, 0] + rowCosts: [5] + colCosts: [26] + out: 0 + - name: "one_row_right" + in: + startPos: [0, 0] + homePos: [0, 4] + rowCosts: [9] + colCosts: [1, 2, 3, 4, 5] + out: 14 + - name: "one_row_left" + in: + startPos: [0, 5] + homePos: [0, 1] + rowCosts: [99] + colCosts: [8, 7, 6, 5, 4, 3] + out: 22 + - name: "one_column_down" + in: + startPos: [0, 0] + homePos: [4, 0] + rowCosts: [10, 1, 2, 3, 4] + colCosts: [77] + out: 10 + - name: "one_column_up" + in: + startPos: [5, 0] + homePos: [1, 0] + rowCosts: [6, 5, 4, 3, 2, 1] + colCosts: [77] + out: 14 + - name: "all_zero" + in: + startPos: [3, 4] + homePos: [0, 0] + rowCosts: [0, 0, 0, 0] + colCosts: [0, 0, 0, 0, 0] + out: 0 + - name: "max_single_move_down" + in: + startPos: [0, 0] + homePos: [1, 0] + rowCosts: [0, 10000] + colCosts: [0] + out: 10000 + - name: "max_single_move_up" + in: + startPos: [1, 0] + homePos: [0, 0] + rowCosts: [10000, 0] + colCosts: [0] + out: 10000 + - name: "max_single_move_right" + in: + startPos: [0, 0] + homePos: [0, 1] + rowCosts: [0] + colCosts: [0, 10000] + out: 10000 + - name: "max_single_move_left" + in: + startPos: [0, 1] + homePos: [0, 0] + rowCosts: [0] + colCosts: [10000, 0] + out: 10000 + - name: "mixed_down_left" + in: + startPos: [0, 4] + homePos: [3, 1] + rowCosts: [8, 1, 9, 2] + colCosts: [7, 6, 5, 4, 3] + out: 27 + - name: "mixed_up_right" + in: + startPos: [4, 0] + homePos: [1, 3] + rowCosts: [2, 8, 1, 7, 6] + colCosts: [9, 1, 5, 4] + out: 26 + - name: "endpoints_grid" + in: + startPos: [0, 0] + homePos: [3, 3] + rowCosts: [1, 10, 100, 1000] + colCosts: [2, 20, 200, 2000] + out: 3330 + - name: "reverse_endpoints_grid" + in: + startPos: [3, 3] + homePos: [0, 0] + rowCosts: [1, 10, 100, 1000] + colCosts: [2, 20, 200, 2000] + out: 333 + - name: "interior_same_row" + in: + startPos: [2, 1] + homePos: [2, 4] + rowCosts: [4, 5, 6, 7] + colCosts: [10, 0, 11, 0, 13] + out: 24 + - name: "interior_same_column" + in: + startPos: [4, 2] + homePos: [1, 2] + rowCosts: [5, 0, 8, 0, 12] + colCosts: [3, 4, 5] + out: 8 + - name: "zero_cost_entered_cells" + in: + startPos: [0, 0] + homePos: [3, 3] + rowCosts: [99, 0, 0, 0] + colCosts: [88, 0, 0, 0] + out: 0 + - name: "zero_cost_start_cells_do_not_count" + in: + startPos: [3, 3] + homePos: [0, 0] + rowCosts: [0, 0, 0, 99] + colCosts: [0, 0, 0, 88] + out: 0 + - name: "repeated_costs" + in: + startPos: [1, 1] + homePos: [5, 4] + rowCosts: [3, 3, 3, 3, 3, 3] + colCosts: [2, 2, 2, 2, 2] + out: 18 + - name: "large_values_mixed" + in: + startPos: [2, 2] + homePos: [7, 8] + rowCosts: [10000, 9999, 1, 10000, 9998, 2, 9997, 3] + colCosts: [10000, 4, 9996, 5, 9995, 6, 9994, 7, 9993] + out: 60000 + - name: "two_by_two_diagonal" + in: + startPos: [0, 0] + homePos: [1, 1] + rowCosts: [17, 23] + colCosts: [31, 37] + out: 60 + - name: "two_by_two_reverse" + in: + startPos: [1, 1] + homePos: [0, 0] + rowCosts: [17, 23] + colCosts: [31, 37] + out: 48 + - name: "three_by_three_center_to_corner" + in: + startPos: [1, 1] + homePos: [0, 0] + rowCosts: [4, 100, 6] + colCosts: [8, 200, 10] + out: 12 + - name: "three_by_three_corner_to_center" + in: + startPos: [0, 0] + homePos: [1, 1] + rowCosts: [4, 100, 6] + colCosts: [8, 200, 10] + out: 300 + - name: "long_row_alternating" + in: + startPos: [0, 1] + homePos: [0, 8] + rowCosts: [1] + colCosts: [0, 1, 0, 1, 0, 1, 0, 1, 0] + out: 3 + - name: "long_column_alternating" + in: + startPos: [1, 0] + homePos: [8, 0] + rowCosts: [0, 1, 0, 1, 0, 1, 0, 1, 0] + colCosts: [0] + out: 3 + - name: "single_row_single_column" + in: + startPos: [0, 0] + homePos: [0, 0] + rowCosts: [10000] + colCosts: [10000] + out: 0 + - name: "same_row_high_cost_unused" + in: + startPos: [0, 1] + homePos: [0, 2] + rowCosts: [10000, 10000] + colCosts: [0, 1, 2] + out: 2 + - name: "same_column_high_cost_unused" + in: + startPos: [1, 0] + homePos: [2, 0] + rowCosts: [0, 1, 2] + colCosts: [10000, 10000] + out: 2 + - name: "generated_rows_forward" + seed: 101 + in: + startPos: [0, 0] + homePos: [99999, 0] + rowCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" + colCosts: [0] + - name: "generated_rows_reverse" + seed: 102 + in: + startPos: [99999, 0] + homePos: [0, 0] + rowCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" + colCosts: [0] + - name: "generated_cols_forward" + seed: 103 + in: + startPos: [0, 0] + homePos: [0, 99999] + rowCosts: [0] + colCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" + - name: "generated_cols_reverse" + seed: 104 + in: + startPos: [0, 99999] + homePos: [0, 0] + rowCosts: [0] + colCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" + - name: "generated_both_axes" + seed: 105 + in: + startPos: [99999, 99999] + homePos: [0, 0] + rowCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" + colCosts: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 10000 + elemType: "int" diff --git a/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/sol.py b/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/sol.py new file mode 100644 index 00000000..51654407 --- /dev/null +++ b/tests/2001-2500/2087. minimum-cost-homecoming-of-a-robot-in-a-grid/sol.py @@ -0,0 +1,94 @@ +class Solution: + def minCost(self, startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int: + + #=========================================================================================================================== + # Look at the constraint. It says 10^5 for a single value of n. + # N * m will be 10^10, right? + # Immediately, the answer is just some greedy approach, not some traversal and some Djikstra and all. + # #=========================================================================================================================== + sr,sc = startPos + er,ec = homePos #Destination coordinate end Row End Column + + + rowtot = 0 + if srer: + rowtot = sum( rowCosts[er: sr]) + + + coltot = 0 + if scec: + coltot = sum( colCosts[ec: sc]) + + + return rowtot + coltot + #=========================================================================================================================== + + + + + + + + # Djikstra on a 2D grid. + ## dijkstras and explore full array + # Djikstra always uses a heap and a dist matrix initialized with infinity startlingly. + #=========================================================================================================================== + n = len(rowCosts) + m = len(colCosts) + + sr,sc = startPos + er,ec = homePos + + + dist = [[10**14]*m for _ in range(n)] + + pq = [(0,sr,sc)] #(dist, r,c) + dist[sr][sc]= 0 + + direct = [[-1,0], [0,1], [1,0], [0,-1]] + + while pq: + d, r, c = heapq.heappop(pq) + + + if d > dist[r][c]: continue #Standard Djikstra optimization. + + + if r == er and c == ec: #reached destination coordinate #ANSWER TIME + return d + + + for dr , dc in direct: + nr, nc = r+dr, c+dc + + if 0<=nr>10^10 + #=========================================================================================================================== \ No newline at end of file diff --git a/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/manifest.yaml b/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/manifest.yaml new file mode 100644 index 00000000..aca43f60 --- /dev/null +++ b/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/manifest.yaml @@ -0,0 +1,350 @@ +entry: + id: 2088 + title: "count-fertile-pyramids-in-a-land" + params: + grid: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().countPyramids({grid})" + rust: "Solution::count_pyramids({grid})" + python3: "Solution().countPyramids({grid})" + python2: "Solution().countPyramids({grid})" + ruby: "count_pyramids({grid})" + java: "new Solution().countPyramids({grid})" + csharp: "new Solution().CountPyramids({grid})" + kotlin: "Solution().countPyramids({grid})" + go: "countPyramids({grid})" + dart: "Solution().countPyramids({grid})" + swift: "Solution().countPyramids({grid})" + typescript: "countPyramids({grid})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().countPyramids(grid, {result})" + checker: | + class Checker: + def countPyramids(self, grid, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + m = len(grid) + n = len(grid[0]) + if m < 1 or n < 1 or any(len(row) != n for row in grid): + return False + def count(rows): + dp = [[0] * n for _ in range(m)] + total = 0 + for i in rows: + for j in range(n): + if grid[i][j] == 1: + if i == m - 1 or j == 0 or j == n - 1: + dp[i][j] = 1 + else: + dp[i][j] = 1 + min(dp[i + 1][j - 1], dp[i + 1][j], dp[i + 1][j + 1]) + total += max(0, dp[i][j] - 1) + return total + down = count(list(range(m - 1, -1, -1))) + updp = [[0] * n for _ in range(m)] + up = 0 + for i in range(m): + for j in range(n): + if grid[i][j] == 1: + if i == 0 or j == 0 or j == n - 1: + updp[i][j] = 1 + else: + updp[i][j] = 1 + min(updp[i - 1][j - 1], updp[i - 1][j], updp[i - 1][j + 1]) + up += max(0, updp[i][j] - 1) + return result == down + up + +seed: 2088 + +tests: + - name: "example_1" + in: + grid: + - [0, 1, 1, 0] + - [1, 1, 1, 1] + out: 2 + - name: "example_2" + in: + grid: + - [1, 1, 1] + - [1, 1, 1] + out: 2 + - name: "example_3" + in: + grid: + - [1, 1, 1, 1, 0] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + - [0, 1, 0, 0, 1] + out: 13 + - name: "single_cell_zero" + in: + grid: + - [0] + out: 0 + - name: "single_cell_one" + in: + grid: + - [1] + out: 0 + - name: "single_row_all_ones" + in: + grid: + - [1, 1, 1, 1, 1, 1] + out: 0 + - name: "single_column_all_ones" + in: + grid: + - [1] + - [1] + - [1] + - [1] + out: 0 + - name: "all_zero_3x4" + in: + grid: + - [0, 0, 0, 0] + - [0, 0, 0, 0] + - [0, 0, 0, 0] + out: 0 + - name: "two_rows_center" + in: + grid: + - [0, 1, 0] + - [1, 1, 1] + out: 1 + - name: "two_rows_inverse" + in: + grid: + - [1, 1, 1] + - [0, 1, 0] + out: 1 + - name: "two_rows_four" + in: + grid: + - [1, 1, 1, 1] + - [1, 1, 1, 1] + out: 4 + - name: "three_by_three_full" + in: + grid: + - [1, 1, 1] + - [1, 1, 1] + - [1, 1, 1] + out: 4 + - name: "four_by_four_full" + in: + grid: + - [1, 1, 1, 1] + - [1, 1, 1, 1] + - [1, 1, 1, 1] + - [1, 1, 1, 1] + out: 12 + - name: "five_by_five_full" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + out: 30 + - name: "wide_center_peak" + in: + grid: + - [0, 0, 1, 0, 0] + - [0, 1, 1, 1, 0] + - [1, 1, 1, 1, 1] + out: 6 + - name: "wide_center_inverse" + in: + grid: + - [1, 1, 1, 1, 1] + - [0, 1, 1, 1, 0] + - [0, 0, 1, 0, 0] + out: 6 + - name: "alternating_rows" + in: + grid: + - [1, 0, 1, 0, 1] + - [0, 1, 0, 1, 0] + - [1, 0, 1, 0, 1] + - [0, 1, 0, 1, 0] + out: 0 + - name: "border_only" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 0, 0, 0, 1] + - [1, 0, 0, 0, 1] + - [1, 1, 1, 1, 1] + out: 0 + - name: "notched_peak" + in: + grid: + - [0, 0, 1, 0, 0] + - [0, 1, 0, 1, 0] + - [1, 1, 1, 1, 1] + out: 2 + - name: "notched_inverse" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 0, 1, 0, 1] + - [0, 0, 1, 0, 0] + out: 1 + - name: "diagonal_noise" + in: + grid: + - [1, 1, 0, 0, 0, 0] + - [0, 1, 1, 0, 0, 0] + - [0, 0, 1, 1, 0, 0] + - [0, 0, 0, 1, 1, 0] + - [0, 0, 0, 0, 1, 1] + out: 0 + - name: "isolated_fertile" + in: + grid: + - [1, 0, 1, 0] + - [0, 0, 0, 0] + - [0, 1, 0, 1] + out: 0 + - name: "left_triangle" + in: + grid: + - [1, 0, 0, 0] + - [1, 1, 0, 0] + - [1, 1, 1, 0] + - [1, 1, 1, 1] + out: 4 + - name: "right_triangle" + in: + grid: + - [0, 0, 0, 1] + - [0, 0, 1, 1] + - [0, 1, 1, 1] + - [1, 1, 1, 1] + out: 4 + - name: "five_by_three_full" + in: + grid: + - [1, 1, 1] + - [1, 1, 1] + - [1, 1, 1] + - [1, 1, 1] + - [1, 1, 1] + out: 8 + - name: "three_by_seven_full" + in: + grid: + - [1, 1, 1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1, 1, 1] + out: 26 + - name: "dense_gap_center" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 1, 0, 1, 1] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + out: 10 + - name: "dense_gap_edge" + in: + grid: + - [1, 1, 1, 1, 1] + - [0, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + - [1, 1, 1, 1, 1] + out: 19 + - name: "generated_small" + seed: 101 + in: + grid: + gen: "array" + len: 7 + of: + gen: "array" + len: 7 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_tall" + seed: 202 + in: + grid: + gen: "array" + len: 40 + of: + gen: "array" + len: 9 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_wide" + seed: 303 + in: + grid: + gen: "array" + len: 8 + of: + gen: "array" + len: 60 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_dense" + seed: 404 + in: + grid: + gen: "array" + len: 25 + of: + gen: "array" + len: 25 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_max_area" + seed: 505 + in: + grid: + gen: "array" + len: 100 + of: + gen: "array" + len: 100 + of: + gen: "int" + min: 0 + max: 1 + - name: "single_row_zeroes" + in: + grid: + - [0, 0, 0, 0, 0, 0, 0] + out: 0 + - name: "single_column_alternating" + in: + grid: + - [1] + - [0] + - [1] + - [0] + - [1] + out: 0 diff --git a/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/sol.py b/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/sol.py new file mode 100644 index 00000000..86176efe --- /dev/null +++ b/tests/2001-2500/2088. count-fertile-pyramids-in-a-land/sol.py @@ -0,0 +1,62 @@ +class Solution: + def finding(self, i, j, grid, dp): + if grid[i][j] == 0: + dp[i][j] = -1 + return -1 + + if dp[i][j] != -2: + return dp[i][j] + + if i + 1 >= len(grid) or j - 1 < 0 or j + 1 >= len(grid[0]): + dp[i][j] = 0 + return 0 + + temp = min( + self.finding(i + 1, j, grid, dp), + self.finding(i + 1, j - 1, grid, dp), + self.finding(i + 1, j + 1, grid, dp), + ) + + dp[i][j] = 1 + temp + return dp[i][j] + + def findingInv(self, i, j, grid, dp): + if grid[i][j] == 0: + dp[i][j] = -1 + return -1 + + if dp[i][j] != -2: + return dp[i][j] + + if i - 1 < 0 or j - 1 < 0 or j + 1 >= len(grid[0]): + dp[i][j] = 0 + return 0 + + temp = min( + self.findingInv(i - 1, j, grid, dp), + self.findingInv(i - 1, j - 1, grid, dp), + self.findingInv(i - 1, j + 1, grid, dp), + ) + + dp[i][j] = 1 + temp + return dp[i][j] + + def countPyramids(self, grid): + m, n = len(grid), len(grid[0]) + ans = 0 + + dp1 = [[-2] * n for _ in range(m)] + + for i in range(m - 1, -1, -1): + for j in range(n - 1, -1, -1): + if grid[i][j]: + ans += self.finding(i, j, grid, dp1) + + dp2 = [[-2] * n for _ in range(m)] + + for i in range(m): + for j in range(n): + if grid[i][j]: + ans += self.findingInv(i, j, grid, dp2) + + return ans \ No newline at end of file diff --git a/tests/2001-2500/2089. find-target-indices-after-sorting-array/manifest.yaml b/tests/2001-2500/2089. find-target-indices-after-sorting-array/manifest.yaml new file mode 100644 index 00000000..17574f56 --- /dev/null +++ b/tests/2001-2500/2089. find-target-indices-after-sorting-array/manifest.yaml @@ -0,0 +1,296 @@ +entry: + id: 2089 + title: "find-target-indices-after-sorting-array" + params: + nums: + type: array + items: + type: int + target: + type: int + call: + cpp: "Solution().targetIndices({nums}, {target})" + rust: "Solution::target_indices({nums}, {target})" + python3: "Solution().targetIndices({nums}, {target})" + python2: "Solution().targetIndices({nums}, {target})" + ruby: "target_indices({nums}, {target})" + java: "new Solution().targetIndices({nums}, {target})" + csharp: "new Solution().TargetIndices({nums}, {target})" + kotlin: "Solution().targetIndices({nums}, {target})" + go: "targetIndices({nums}, {target})" + dart: "Solution().targetIndices({nums}, {target})" + swift: "Solution().targetIndices({nums}, {target})" + typescript: "targetIndices({nums}, {target})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().targetIndices(nums, target, {result})" + checker: | + class Checker: + def targetIndices(self, nums, target, result): + if not isinstance(result, list) or any(isinstance(x, bool) or not isinstance(x, int) for x in result): + return False + start = sum(x < target for x in nums) + count = sum(x == target for x in nums) + return result == list(range(start, start + count)) + +seed: 2089 + +tests: + - name: "example_1" + in: + nums: [1, 2, 5, 2, 3] + target: 2 + out: [1, 2] + - name: "example_2" + in: + nums: [1, 2, 5, 2, 3] + target: 3 + out: [3] + - name: "example_3" + in: + nums: [1, 2, 5, 2, 3] + target: 5 + out: [4] + - name: "single_match" + in: + nums: [7] + target: 7 + out: [0] + - name: "single_absent" + in: + nums: [7] + target: 6 + out: [] + - name: "single_minimum" + in: + nums: [1] + target: 1 + out: [0] + - name: "single_maximum" + in: + nums: [100] + target: 100 + out: [0] + - name: "all_equal_min" + in: + nums: [1, 1, 1, 1, 1] + target: 1 + out: [0, 1, 2, 3, 4] + - name: "all_equal_max" + in: + nums: [100, 100, 100, 100] + target: 100 + out: [0, 1, 2, 3] + - name: "all_target_middle_value" + in: + nums: [50, 50, 50] + target: 50 + out: [0, 1, 2] + - name: "target_absent_below" + in: + nums: [2, 4, 6, 8] + target: 1 + out: [] + - name: "target_absent_above" + in: + nums: [2, 4, 6, 8] + target: 100 + out: [] + - name: "target_absent_gap" + in: + nums: [1, 3, 5, 7] + target: 4 + out: [] + - name: "minimum_with_larger_values" + in: + nums: [4, 1, 3, 2] + target: 1 + out: [0] + - name: "maximum_with_smaller_values" + in: + nums: [4, 1, 3, 2] + target: 4 + out: [3] + - name: "duplicates_at_start" + in: + nums: [3, 1, 3, 2, 3] + target: 3 + out: [2, 3, 4] + - name: "duplicates_at_end" + in: + nums: [9, 8, 7, 9, 9] + target: 9 + out: [2, 3, 4] + - name: "duplicates_scattered" + in: + nums: [5, 2, 8, 2, 4, 2, 9] + target: 2 + out: [0, 1, 2] + - name: "two_target_values" + in: + nums: [10, 1, 10] + target: 10 + out: [1, 2] + - name: "target_at_sorted_boundary" + in: + nums: [3, 3, 1, 2] + target: 3 + out: [2, 3] + - name: "interleaved_values" + in: + nums: [6, 2, 5, 2, 4, 2, 1] + target: 4 + out: [4] + - name: "many_less" + in: + nums: [1, 1, 1, 2, 3, 4, 5] + target: 5 + out: [6] + - name: "many_greater" + in: + nums: [5, 6, 7, 8, 9, 10] + target: 5 + out: [0] + - name: "alternating_targets" + in: + nums: [2, 1, 2, 1, 2, 1] + target: 2 + out: [3, 4, 5] + - name: "long_duplicate_run" + in: + nums: [9, 4, 4, 4, 1, 4, 8, 4, 2, 4] + target: 4 + out: [2, 3, 4, 5, 6, 7] + - name: "values_at_limits" + in: + nums: [100, 1, 100, 1, 50] + target: 50 + out: [2] + - name: "near_limit_target" + in: + nums: [99, 100, 1, 99, 50] + target: 99 + out: [2, 3] + - name: "already_sorted" + in: + nums: [1, 2, 2, 3, 4, 5] + target: 2 + out: [1, 2] + - name: "reverse_sorted" + in: + nums: [6, 5, 4, 3, 2, 1] + target: 4 + out: [3] + - name: "every_other_value" + in: + nums: [1, 2, 1, 2, 1, 2, 1, 2] + target: 1 + out: [0, 1, 2, 3] + - name: "target_once_after_duplicates" + in: + nums: [2, 2, 2, 5, 5, 7, 9] + target: 7 + out: [5] + - name: "target_once_before_duplicates" + in: + nums: [2, 2, 5, 5, 7, 9, 9] + target: 5 + out: [2, 3] + - name: "mixed_full_range" + in: + nums: [100, 1, 50, 100, 1, 50, 75, 25] + target: 50 + out: [3, 4] + - name: "gen_small_random" + seed: 2101 + in: + nums: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + elemType: "int" + target: + gen: "int" + min: 1 + max: 100 + - name: "gen_duplicate_heavy" + seed: 2102 + in: + nums: + gen: "array" + len: + gen: "int" + min: 20 + max: 60 + of: + gen: "int" + min: 1 + max: 3 + distinct: false + sorted: false + elemType: "int" + target: 2 + - name: "gen_medium_random" + seed: 2103 + in: + nums: + gen: "array" + len: + gen: "int" + min: 60 + max: 100 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + elemType: "int" + target: + gen: "int" + min: 1 + max: 100 + - name: "gen_maximum_uniform_target" + seed: 2104 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: 42 + max: 42 + distinct: false + sorted: false + elemType: "int" + target: 42 + - name: "gen_maximum_full_range" + seed: 2105 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + elemType: "int" + target: 100 diff --git a/tests/2001-2500/2089. find-target-indices-after-sorting-array/sol.py b/tests/2001-2500/2089. find-target-indices-after-sorting-array/sol.py new file mode 100644 index 00000000..f3222c8d --- /dev/null +++ b/tests/2001-2500/2089. find-target-indices-after-sorting-array/sol.py @@ -0,0 +1,15 @@ +class Solution: + def targetIndices(self, nums, target): + r = [] + less = 0 + more = 0 + for c in nums: + if c < target: + less += 1 + if c > target: + more += 1 + # Resulting length needs to be n - less - more + # Starting index is less, ending is n - more + for i in range(less, len(nums) - more): + r.append(i) + return r \ No newline at end of file diff --git a/tests/2001-2500/2090. k-radius-subarray-averages/manifest.yaml b/tests/2001-2500/2090. k-radius-subarray-averages/manifest.yaml new file mode 100644 index 00000000..e12c5ebd --- /dev/null +++ b/tests/2001-2500/2090. k-radius-subarray-averages/manifest.yaml @@ -0,0 +1,246 @@ +entry: + id: 2090 + title: "k-radius-subarray-averages" + params: + nums: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().getAverages({nums}, {k})" + rust: "Solution::get_averages({nums}, {k})" + python3: "Solution.getAverages({nums}, {k})" + python2: "Solution().getAverages({nums}, {k})" + ruby: "get_averages({nums}, {k})" + java: "new Solution().getAverages({nums}, {k})" + csharp: "new Solution().GetAverages({nums}, {k})" + kotlin: "Solution().getAverages({nums}, {k})" + go: "getAverages({nums}, {k})" + dart: "Solution().getAverages({nums}, {k})" + swift: "Solution().getAverages({nums}, {k})" + typescript: "getAverages({nums}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().getAverages(nums, k, {result})" + checker: | + class Checker: + def getAverages(self, nums, k, result): + if not isinstance(result, list) or len(result) != len(nums): + return False + width = 2 * k + 1 + expected = [-1] * len(nums) + if width <= len(nums): + for i in range(k, len(nums) - k): + expected[i] = sum(nums[i-k:i+k+1]) // width + return result == expected + +seed: 20902090 + +tests: + - name: "example_1" + in: + nums: [7, 4, 3, 9, 1, 8, 5, 2, 6] + k: 3 + out: [-1, -1, -1, 5, 4, 4, -1, -1, -1] + - name: "example_2_k_zero" + in: + nums: [100000] + k: 0 + out: [100000] + - name: "example_3_oversized_k" + in: + nums: [8] + k: 100000 + out: [-1] + - name: "single_zero_k" + in: + nums: [0] + k: 0 + out: [0] + - name: "two_elements_radius_one" + in: + nums: [1, 9] + k: 1 + - name: "exact_window" + in: + nums: [1, 2, 3, 4, 5] + k: 2 + - name: "window_one_all_values" + in: + nums: [0, 1, 99999, 100000, 42] + k: 0 + - name: "constant_values" + in: + nums: [7, 7, 7, 7, 7, 7, 7] + k: 2 + - name: "zeros_and_maximums" + in: + nums: [0, 100000, 0, 100000, 0, 100000, 0] + k: 1 + - name: "even_sum_truncation" + in: + nums: [1, 1, 1, 2, 2, 2, 3, 3] + k: 1 + - name: "shorter_than_window" + in: + nums: [4, 8, 15, 16, 23] + k: 3 + - name: "one_valid_center" + in: + nums: [10, 20, 30, 40, 50, 60, 70] + k: 3 + - name: "negative_not_allowed_zero_mix" + in: + nums: [0, 0, 1, 0, 0, 1, 0, 0] + k: 2 + - name: "alternating_small" + in: + nums: [1, 0, 1, 0, 1, 0, 1, 0, 1] + k: 2 + - name: "large_middle_values" + in: + nums: [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992] + k: 4 + - name: "k_near_boundary" + in: + nums: [3, 6, 9, 12, 15, 18] + k: 2 + - name: "repeated_blocks" + in: + nums: [2, 2, 2, 9, 9, 9, 2, 2, 2, 9, 9, 9] + k: 1 + - name: "prime_pattern" + in: + nums: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] + k: 2 + - name: "powers_pattern" + in: + nums: [1, 2, 4, 8, 16, 32, 64, 128] + k: 1 + - name: "long_radius_one" + in: + nums: [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5] + k: 1 + - name: "long_radius_four" + in: + nums: [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5] + k: 4 + - name: "all_maximum" + in: + nums: [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000] + k: 3 + - name: "mostly_zero" + in: + nums: [0, 0, 0, 0, 100000, 0, 0, 0, 0] + k: 2 + - name: "increasing_ten" + in: + nums: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] + k: 3 + - name: "decreasing_ten" + in: + nums: [90, 80, 70, 60, 50, 40, 30, 20, 10, 0] + k: 2 + - name: "irregular_remainders" + in: + nums: [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1] + k: 3 + - name: "radius_zero_long" + in: + nums: [12, 0, 999, 45, 100000, 3, 77, 8] + k: 0 + - name: "radius_equals_two" + in: + nums: [8, 6, 7, 5, 3, 0, 9] + k: 2 + - name: "all_boundary_invalid" + in: + nums: [1, 2, 3, 4] + k: 2 + - name: "large_sum_window" + in: + nums: [100000, 100000, 99999, 99999, 100000, 99999, 99999, 100000, 100000] + k: 4 + - name: "generated_small" + seed: 101 + in: + nums: + gen: "array" + len: + gen: "int" + min: 1 + max: 25 + of: + gen: "int" + min: 0 + max: 100000 + k: + gen: "int" + min: 0 + max: 25 + - name: "generated_medium" + seed: 202 + in: + nums: + gen: "array" + len: + gen: "int" + min: 50 + max: 250 + of: + gen: "int" + min: 0 + max: 100000 + k: + gen: "int" + min: 0 + max: 250 + - name: "generated_small_k" + seed: 303 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: 0 + max: 10 + k: + gen: "int" + min: 0 + max: 4 + - name: "stress_max_length" + seed: 404 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 100000 + k: + gen: "int" + min: 0 + max: 100000 + - name: "stress_large_valid_windows" + seed: 505 + in: + nums: + gen: "array" + len: 99999 + of: + gen: "int" + min: 0 + max: 100000 + k: 49999 diff --git a/tests/2001-2500/2090. k-radius-subarray-averages/sol.py b/tests/2001-2500/2090. k-radius-subarray-averages/sol.py new file mode 100644 index 00000000..0d9d1a84 --- /dev/null +++ b/tests/2001-2500/2090. k-radius-subarray-averages/sol.py @@ -0,0 +1,20 @@ +class Solution: + def getAverages(nums: list[int], k: int) -> list[int]: + n = len(nums) + avgs = [-1] * n + window_size = 2 * k + 1 + + # If window size exceeds array length, no average can be computed + if window_size > n: + return avgs + + # Calculate initial window sum for the first center index (which is at k) + window_sum = sum(nums[:window_size]) + avgs[k] = window_sum // window_size + + # Slide the window across the remaining valid center indices + for i in range(k + 1, n - k): + window_sum += nums[i + k] - nums[i - k - 1] + avgs[i] = window_sum // window_size + + return avgs diff --git a/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/manifest.yaml b/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/manifest.yaml new file mode 100644 index 00000000..f1309a13 --- /dev/null +++ b/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/manifest.yaml @@ -0,0 +1,252 @@ +entry: + id: 2091 + title: "removing-minimum-and-maximum-from-array" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().minimumDeletions({nums})" + rust: "Solution::minimum_deletions({nums})" + python3: "Solution().minimumDeletions({nums})" + python2: "Solution().minimumDeletions({nums})" + ruby: "minimum_deletions({nums})" + java: "new Solution().minimumDeletions({nums})" + csharp: "new Solution().MinimumDeletions({nums})" + kotlin: "Solution().minimumDeletions({nums})" + go: "minimumDeletions({nums})" + dart: "Solution().minimumDeletions({nums})" + swift: "Solution().minimumDeletions({nums})" + typescript: "minimumDeletions({nums})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumDeletions(nums, {result})" + checker: | + class Checker: + def minimumDeletions(self, nums, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(nums) + lo = nums.index(min(nums)) + hi = nums.index(max(nums)) + i, j = sorted((lo, hi)) + expected = min(j + 1, n - i, i + 1 + n - j) + return result == expected + +seed: 2091 + +tests: + - name: "example_1" + in: + nums: [2, 10, 7, 5, 4, 1, 8, 6] + out: 5 + - name: "example_2" + in: + nums: [0, -4, 19, 1, 8, -2, -3, 5] + out: 3 + - name: "example_3_singleton" + in: + nums: [101] + out: 1 + - name: "two_elements" + in: + nums: [-100000, 100000] + out: 2 + - name: "min_front_max_back" + in: + nums: [-9, -3, 0, 4, 12] + out: 2 + - name: "max_front_min_back" + in: + nums: [12, 4, 0, -3, -9] + out: 2 + - name: "both_at_front" + in: + nums: [100, -100, 1, 2, 3, 4] + out: 2 + - name: "both_at_back" + in: + nums: [1, 2, 3, 4, -100, 100] + out: 2 + - name: "adjacent_middle" + in: + nums: [8, 7, -5, 20, 4, 3] + out: 4 + - name: "middle_pair_front_strategy" + in: + nums: [5, -7, 30, 8, 9, 10, 11] + out: 3 + - name: "middle_pair_back_strategy" + in: + nums: [5, 6, 7, 8, -7, 30, 11] + out: 3 + - name: "one_each_side" + in: + nums: [-50, 4, 5, 6, 99] + out: 2 + - name: "min_second_max_second" + in: + nums: [4, -20, 70, 8, 9] + out: 3 + - name: "min_second_max_penultimate" + in: + nums: [4, -20, 7, 8, 70, 9] + out: 4 + - name: "min_penultimate_max_second" + in: + nums: [4, 70, 7, 8, -20, 9] + out: 4 + - name: "min_and_max_deep" + in: + nums: [5, 6, 7, 8, -100, 9, 10, 11, 100] + out: 5 + - name: "front_cheaper_than_back" + in: + nums: [99, -4, 3, 5, 8, 20, 7] + out: 2 + - name: "back_cheaper_than_front" + in: + nums: [7, 20, 8, 5, 3, -4, 99] + out: 2 + - name: "split_removals" + in: + nums: [100, 2, 3, 4, -100, 5, 6] + out: 4 + - name: "negative_values" + in: + nums: [-8, -2, -100, -4, -1] + out: 3 + - name: "zero_and_boundaries" + in: + nums: [0, 99999, -100000, 42, -1] + out: 3 + - name: "maximum_bounds_interior" + in: + nums: [-99999, 1, 100000, 2, 99998, -100000] + out: 4 + - name: "longer_front_pair" + in: + nums: [100000, -100000, 1, 2, 3, 4, 5, 6, 7, 8] + out: 2 + - name: "longer_back_pair" + in: + nums: [1, 2, 3, 4, 5, 6, 7, 8, -100000, 100000] + out: 2 + - name: "interleaved_extremes" + in: + nums: [4, 100, 3, -100, 2, 1, 0] + out: 4 + - name: "near_front_and_back" + in: + nums: [100, 1, 2, 3, 4, -100] + out: 2 + - name: "balanced_positions" + in: + nums: [1, 2, 3, -10, 5, 20, 7, 8] + out: 5 + - name: "all_distinct_small" + in: + nums: [6, -2, 14, 0, 9, -8, 3] + out: 5 + - name: "ascending" + in: + nums: [-10, -5, 0, 5, 10] + out: 2 + - name: "descending" + in: + nums: [10, 5, 0, -5, -10] + out: 2 + - name: "three_middle_extremes" + in: + nums: [7, -20, 100, 4, 9] + out: 3 + - name: "extremes_at_indices_2_5" + in: + nums: [1, 2, -50, 3, 4, 80, 5, 6] + out: 6 + - name: "extremes_at_indices_3_4" + in: + nums: [1, 2, 3, -50, 80, 5, 6] + out: 4 + - name: "large_magnitude_mix" + in: + nums: [999, -999, 50000, -50000, 100000, -100000, 1] + out: 3 + - name: "single_extreme_reverse_end" + in: + nums: [99997, 99998, 99999, 100000] + out: 2 + - name: "generated_small_distinct" + seed: 101 + in: + nums: + gen: "array" + len: 17 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: true + sorted: false + elemType: "int" + - name: "generated_medium_distinct" + seed: 202 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: true + sorted: false + elemType: "int" + - name: "generated_boundary_values" + seed: 303 + in: + nums: + gen: "array" + len: 256 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: true + sorted: false + elemType: "int" + - name: "stress_near_maximum" + seed: 404 + in: + nums: + gen: "array" + len: 99999 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: true + sorted: false + elemType: "int" + - name: "stress_maximum" + seed: 505 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: true + sorted: false + elemType: "int" diff --git a/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/sol.py b/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/sol.py new file mode 100644 index 00000000..984c7d8d --- /dev/null +++ b/tests/2001-2500/2091. removing-minimum-and-maximum-from-array/sol.py @@ -0,0 +1,4 @@ +class Solution: + def minimumDeletions(self, a: List[int]) -> int: + n,i,j = len(a),*sorted([a.index(min(a)),a.index(max(a))]) + return min(j+1,n-i,i+1+n-j) \ No newline at end of file diff --git a/tests/2001-2500/2092. find-all-people-with-secret/manifest.yaml b/tests/2001-2500/2092. find-all-people-with-secret/manifest.yaml new file mode 100644 index 00000000..4b2479b3 --- /dev/null +++ b/tests/2001-2500/2092. find-all-people-with-secret/manifest.yaml @@ -0,0 +1,438 @@ +entry: + id: 2092 + title: "find-all-people-with-secret" + params: + n: + type: int + meetings: + type: array + items: + type: array + items: + type: int + firstPerson: + type: int + call: + cpp: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + rust: "Solution::find_all_people({n}, {meetings}, {firstPerson})" + python3: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + python2: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + ruby: "find_all_people({n}, {meetings}, {firstPerson})" + java: "new Solution().findAllPeople({n}, {meetings}, {firstPerson})" + csharp: "new Solution().FindAllPeople({n}, {meetings}, {firstPerson})" + kotlin: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + go: "findAllPeople({n}, {meetings}, {firstPerson})" + dart: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + swift: "Solution().findAllPeople({n}, {meetings}, {firstPerson})" + typescript: "findAllPeople({n}, {meetings}, {firstPerson})" + +judge: + type: "ignore_order" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().findAllPeople(n, meetings, firstPerson, {result})" + checker: | + class Checker: + def findAllPeople(self, n, meetings, firstPerson, result): + if not isinstance(result, list): + return False + known = {0, firstPerson} + by_time = {} + for x, y, t in meetings: + by_time.setdefault(t, []).append((x, y)) + for t in sorted(by_time): + graph = {} + for x, y in by_time[t]: + graph.setdefault(x, []).append(y) + graph.setdefault(y, []).append(x) + queue = [p for x, y in by_time[t] for p in (x, y) if p in known] + seen = set(queue) + for p in queue: + for q in graph.get(p, []): + if q not in seen: + seen.add(q) + queue.append(q) + known.update(seen) + return set(result) == known and len(result) == len(known) + +seed: 2092 + +tests: + - name: "example_chain" + in: + n: 6 + meetings: + - [1, 2, 5] + - [2, 3, 8] + - [1, 5, 10] + firstPerson: 1 + out: [0, 1, 2, 3, 5] + - name: "example_late_meeting" + in: + n: 4 + meetings: + - [3, 1, 3] + - [1, 2, 2] + - [0, 3, 3] + firstPerson: 3 + out: [0, 1, 3] + - name: "example_same_time_chain" + in: + n: 5 + meetings: + - [3, 4, 2] + - [1, 2, 1] + - [2, 3, 1] + firstPerson: 1 + out: [0, 1, 2, 3, 4] + - name: "only_initial_pair" + in: + n: 2 + meetings: + - [0, 1, 1] + firstPerson: 1 + out: [0, 1] + - name: "no_reachable_meetings" + in: + n: 5 + meetings: + - [2, 3, 1] + - [3, 4, 2] + firstPerson: 1 + out: [0, 1] + - name: "direct_first_person" + in: + n: 5 + meetings: + - [1, 4, 1] + firstPerson: 1 + out: [0, 1, 4] + - name: "same_time_transitive" + in: + n: 6 + meetings: + - [1, 2, 7] + - [2, 3, 7] + - [3, 4, 7] + - [4, 5, 7] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "same_time_disconnected" + in: + n: 7 + meetings: + - [1, 2, 4] + - [3, 4, 4] + - [5, 6, 4] + firstPerson: 1 + out: [0, 1, 2] + - name: "order_independent_same_time" + in: + n: 6 + meetings: + - [4, 5, 9] + - [2, 3, 9] + - [1, 2, 9] + - [3, 4, 9] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "future_cannot_backpropagate" + in: + n: 5 + meetings: + - [2, 3, 5] + - [1, 2, 10] + firstPerson: 1 + out: [0, 1, 2] + - name: "past_meeting_unavailable" + in: + n: 5 + meetings: + - [1, 2, 10] + - [2, 3, 1] + - [3, 4, 2] + firstPerson: 1 + out: [0, 1, 2] + - name: "duplicate_edges" + in: + n: 4 + meetings: + - [1, 2, 1] + - [1, 2, 1] + - [2, 3, 2] + firstPerson: 1 + out: [0, 1, 2, 3] + - name: "repeated_times_progress" + in: + n: 8 + meetings: + - [1, 2, 1] + - [2, 3, 1] + - [3, 4, 2] + - [4, 5, 2] + - [5, 6, 3] + - [6, 7, 4] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5, 6, 7] + - name: "cycle_unreachable" + in: + n: 7 + meetings: + - [2, 3, 1] + - [3, 4, 1] + - [4, 2, 1] + - [5, 6, 2] + firstPerson: 1 + out: [0, 1] + - name: "cycle_reached_late" + in: + n: 7 + meetings: + - [1, 2, 3] + - [2, 3, 4] + - [3, 1, 4] + - [3, 4, 5] + - [4, 5, 6] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "first_person_max_id" + in: + n: 10 + meetings: + - [9, 8, 1] + - [8, 7, 2] + firstPerson: 9 + out: [0, 7, 8, 9] + - name: "zero_meeting_at_time_one" + in: + n: 6 + meetings: + - [0, 5, 1] + - [2, 4, 1] + - [1, 3, 2] + firstPerson: 1 + out: [0, 1, 3, 5] + - name: "all_meet_at_final_time" + in: + n: 6 + meetings: + - [1, 2, 1] + - [2, 3, 100000] + - [3, 4, 100000] + - [4, 5, 100000] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "isolated_zero_edge" + in: + n: 8 + meetings: + - [0, 2, 1] + - [3, 4, 2] + - [5, 6, 3] + - [6, 7, 4] + firstPerson: 1 + out: [0, 1, 2] + - name: "branching" + in: + n: 9 + meetings: + - [1, 2, 2] + - [1, 3, 2] + - [2, 4, 3] + - [3, 5, 3] + - [4, 6, 4] + - [5, 7, 4] + - [6, 8, 5] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5, 6, 7, 8] + - name: "branch_blocked_by_time" + in: + n: 8 + meetings: + - [1, 2, 5] + - [2, 3, 4] + - [1, 4, 6] + - [4, 5, 7] + - [3, 6, 8] + - [5, 7, 9] + firstPerson: 1 + out: [0, 1, 2, 4, 5, 7] + - name: "multiple_components_one_reached" + in: + n: 10 + meetings: + - [1, 2, 1] + - [2, 3, 2] + - [4, 5, 1] + - [5, 6, 2] + - [7, 8, 3] + - [8, 9, 4] + firstPerson: 1 + out: [0, 1, 2, 3] + - name: "meeting_with_known_both" + in: + n: 5 + meetings: + - [0, 1, 1] + - [1, 2, 2] + - [0, 2, 3] + - [2, 4, 4] + firstPerson: 1 + out: [0, 1, 2, 4] + - name: "late_bridge" + in: + n: 7 + meetings: + - [1, 2, 1] + - [3, 4, 1] + - [2, 3, 2] + - [4, 5, 2] + - [5, 6, 3] + firstPerson: 1 + out: [0, 1, 2, 3] + - name: "bridge_too_early" + in: + n: 7 + meetings: + - [2, 3, 1] + - [1, 2, 2] + - [3, 4, 2] + - [4, 5, 3] + - [5, 6, 4] + firstPerson: 1 + out: [0, 1, 2] + - name: "no_chain_after_dead_end" + in: + n: 6 + meetings: + - [1, 2, 2] + - [3, 4, 1] + - [4, 5, 1] + - [2, 3, 1] + firstPerson: 1 + out: [0, 1, 2] + - name: "long_sequential_chain" + in: + n: 12 + meetings: + - [1, 2, 1] + - [2, 3, 2] + - [3, 4, 3] + - [4, 5, 4] + - [5, 6, 5] + - [6, 7, 6] + - [7, 8, 7] + - [8, 9, 8] + - [9, 10, 9] + - [10, 11, 10] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + - name: "high_time_sparse" + in: + n: 6 + meetings: + - [1, 2, 99998] + - [2, 3, 99999] + - [3, 4, 100000] + - [0, 5, 100000] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "same_time_cycle_and_tail" + in: + n: 8 + meetings: + - [1, 2, 50] + - [2, 3, 50] + - [3, 1, 50] + - [3, 4, 50] + - [4, 5, 50] + - [5, 6, 51] + - [6, 7, 52] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5, 6, 7] + - name: "large_n_few_meetings" + in: + n: 100000 + meetings: + - [99999, 99998, 1] + - [1, 99999, 2] + - [99998, 99997, 3] + - [50000, 50001, 4] + firstPerson: 1 + out: [0, 1, 99999] + - name: "large_n_high_ids_disconnected" + in: + n: 100000 + meetings: + - [99998, 99999, 1] + - [99997, 99998, 2] + - [2, 3, 3] + - [1, 2, 4] + firstPerson: 1 + out: [0, 1, 2] + - name: "dense_small_same_time" + in: + n: 10 + meetings: + - [1, 2, 10] + - [1, 3, 10] + - [1, 4, 10] + - [2, 5, 10] + - [3, 6, 10] + - [4, 7, 10] + - [5, 8, 10] + - [6, 9, 10] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + - name: "late_first_connection" + in: + n: 6 + meetings: + - [2, 3, 1] + - [3, 4, 2] + - [1, 2, 100000] + - [4, 5, 100000] + firstPerson: 1 + out: [0, 1, 2] + - name: "same_time_receives_and_shares" + in: + n: 6 + meetings: + - [4, 5, 20] + - [3, 4, 20] + - [2, 3, 20] + - [1, 2, 20] + firstPerson: 1 + out: [0, 1, 2, 3, 4, 5] + - name: "late_unreachable_component" + in: + n: 9 + meetings: + - [1, 2, 1] + - [2, 3, 2] + - [4, 5, 100000] + - [5, 6, 100000] + - [6, 7, 100000] + - [7, 8, 100000] + firstPerson: 1 + out: [0, 1, 2, 3] + - name: "all_people_already_connected" + in: + n: 10 + meetings: + - [0, 1, 1] + - [2, 3, 1] + - [4, 5, 1] + - [6, 7, 1] + - [8, 9, 1] + - [1, 2, 2] + - [3, 4, 2] + - [5, 6, 2] + - [7, 8, 2] + firstPerson: 1 + out: [0, 1, 2] diff --git a/tests/2001-2500/2092. find-all-people-with-secret/sol.py b/tests/2001-2500/2092. find-all-people-with-secret/sol.py new file mode 100644 index 00000000..ed59ca59 --- /dev/null +++ b/tests/2001-2500/2092. find-all-people-with-secret/sol.py @@ -0,0 +1,42 @@ +from collections import defaultdict, deque + +class Solution: + def findAllPeople(self, n, meet, fp): + + # Group meetings in increasing order of time + timeMeetings = defaultdict(list) + for x, y, t in meet: + timeMeetings[t].append((x, y)) + + # ks -> knows secret + ks = [False] * n + ks[0] = True + ks[fp] = True + + for t in sorted(timeMeetings.keys()): + meetings = timeMeetings[t] + + # Build adjacency list for time t only + meetList = defaultdict(list) + for x, y in meetings: + meetList[x].append(y) + meetList[y].append(x) + + # Find starting points + start = set() + for x, y in meetings: + if ks[x]: + start.add(x) + if ks[y]: + start.add(y) + + # BFS + q = deque(start) + while q: + person = q.popleft() + for nextPerson in meetList[person]: + if not ks[nextPerson]: + ks[nextPerson] = True + q.append(nextPerson) + + return [i for i in range(n) if ks[i]] \ No newline at end of file diff --git a/tests/2001-2500/2094. finding-3-digit-even-numbers/manifest.yaml b/tests/2001-2500/2094. finding-3-digit-even-numbers/manifest.yaml new file mode 100644 index 00000000..a5043cf1 --- /dev/null +++ b/tests/2001-2500/2094. finding-3-digit-even-numbers/manifest.yaml @@ -0,0 +1,195 @@ +entry: + id: 2094 + title: "finding-3-digit-even-numbers" + params: + digits: + type: array + items: + type: int + call: + cpp: "Solution().findEvenNumbers({digits})" + rust: "Solution::find_even_numbers({digits})" + python3: "Solution().findEvenNumbers({digits})" + python2: "Solution().findEvenNumbers({digits})" + ruby: "find_even_numbers({digits})" + java: "new Solution().findEvenNumbers({digits})" + csharp: "new Solution().FindEvenNumbers({digits})" + kotlin: "Solution().findEvenNumbers({digits})" + go: "findEvenNumbers({digits})" + dart: "Solution().findEvenNumbers({digits})" + swift: "Solution().findEvenNumbers({digits})" + typescript: "findEvenNumbers({digits})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().findEvenNumbers(digits, {result})" + checker: | + class Checker: + def findEvenNumbers(self, digits, result): + if not isinstance(result, list): + return False + counts = [0] * 10 + for digit in digits: + if not isinstance(digit, int) or digit < 0 or digit > 9: + return False + counts[digit] += 1 + expected = [] + for hundreds in range(1, 10): + for tens in range(10): + for ones in range(0, 10, 2): + need = [0] * 10 + need[hundreds] += 1 + need[tens] += 1 + need[ones] += 1 + if all(need[d] <= counts[d] for d in range(10)): + expected.append(100 * hundreds + 10 * tens + ones) + return result == expected + +seed: 2094 + +tests: + - name: "example_1" + in: + digits: [2, 1, 3, 0] + out: [102, 120, 130, 132, 210, 230, 302, 310, 312, 320] + - name: "example_2_duplicates" + in: + digits: [2, 2, 8, 8, 2] + out: [222, 228, 282, 288, 822, 828, 882] + - name: "example_3_no_even_digit" + in: + digits: [3, 7, 5] + out: [] + - name: "all_zero" + in: + digits: [0, 0, 0] + out: [] + - name: "three_distinct_no_zero" + in: + digits: [1, 2, 4] + out: [124, 142, 214, 412] + - name: "all_odd_digits" + in: + digits: [1, 3, 5, 7, 9] + out: [] + - name: "zero_even_digits" + in: + digits: [0, 2, 4] + out: [204, 240, 402, 420] + - name: "zero_one_two" + in: + digits: [0, 1, 2] + out: [102, 120, 210] + - name: "two_zeros_one_even" + in: + digits: [0, 0, 2] + out: [200] + - name: "repeated_odd_and_even" + in: + digits: [1, 1, 2] + out: [112] + - name: "one_odd_two_even" + in: + digits: [1, 2, 2] + out: [122, 212] + - name: "same_digit_even" + in: + digits: [8, 8, 8] + out: [888] + - name: "zero_and_three_even_choices" + in: + digits: [0, 4, 6, 8] + out: [406, 408, 460, 468, 480, 486, 604, 608, 640, 648, 680, 684, 804, 806, 840, 846, 860, 864] + - name: "mixed_zero_and_odd" + in: + digits: [9, 0, 2, 5] + out: [250, 290, 502, 520, 590, 592, 902, 920, 950, 952] + - name: "two_zero_supply" + in: + digits: [1, 0, 0, 2] + out: [100, 102, 120, 200, 210] + - name: "three_of_each" + in: + digits: [1, 1, 1, 2, 2, 2] + out: [112, 122, 212, 222] + - name: "all_digits_stress" + in: + digits: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + - name: "two_high_pairs" + in: + digits: [9, 9, 8, 8, 7, 6] + out: [678, 688, 698, 768, 786, 788, 796, 798, 868, 876, 878, 886, 896, 898, 968, 976, 978, 986, 988, 996, 998] + - name: "paired_zero_one_two" + in: + digits: [0, 0, 1, 1, 2, 2] + out: [100, 102, 110, 112, 120, 122, 200, 202, 210, 212, 220] + - name: "all_even_digits" + in: + digits: [2, 4, 6, 8, 0] + out: [204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 402, 406, 408, 420, 426, 428, 460, 462, 468, 480, 482, 486, 602, 604, 608, 620, 624, 628, 640, 642, 648, 680, 682, 684, 802, 804, 806, 820, 824, 826, 840, 842, 846, 860, 862, 864] + - name: "repeated_four_six" + in: + digits: [1, 4, 4, 6, 6] + out: [144, 146, 164, 166, 414, 416, 446, 464, 466, 614, 616, 644, 646, 664] + - name: "three_threes_two_fours" + in: + digits: [3, 3, 3, 4, 4] + out: [334, 344, 434] + - name: "four_distinct_high" + in: + digits: [5, 6, 7, 8] + out: [568, 576, 578, 586, 658, 678, 756, 758, 768, 786, 856, 876] + - name: "zero_three_six_nine" + in: + digits: [0, 3, 6, 9] + out: [306, 360, 390, 396, 630, 690, 906, 930, 936, 960] + - name: "six_distinct" + in: + digits: [1, 2, 3, 4, 5, 6] + out: [124, 126, 132, 134, 136, 142, 146, 152, 154, 156, 162, 164, 214, 216, 234, 236, 246, 254, 256, 264, 312, 314, 316, 324, 326, 342, 346, 352, 354, 356, 362, 364, 412, 416, 426, 432, 436, 452, 456, 462, 512, 514, 516, 524, 526, 532, 534, 536, 542, 546, 562, 564, 612, 614, 624, 632, 634, 642, 652, 654] + - name: "three_twos_with_zero_three" + in: + digits: [0, 2, 2, 2, 3] + out: [202, 220, 222, 230, 232, 302, 320, 322] + - name: "double_zero_high_digits" + in: + digits: [7, 8, 9, 0, 0] + out: [700, 708, 780, 790, 798, 800, 870, 890, 900, 908, 970, 978, 980] + - name: "double_nine_one_eight" + in: + digits: [1, 8, 9, 9] + out: [198, 918, 998] + - name: "three_eights_with_zero_one" + in: + digits: [0, 1, 8, 8, 8] + out: [108, 180, 188, 808, 810, 818, 880, 888] + - name: "seven_digit_range" + in: + digits: [2, 3, 4, 5, 6, 7, 8] + out: [234, 236, 238, 246, 248, 254, 256, 258, 264, 268, 274, 276, 278, 284, 286, 324, 326, 328, 342, 346, 348, 352, 354, 356, 358, 362, 364, 368, 372, 374, 376, 378, 382, 384, 386, 426, 428, 432, 436, 438, 452, 456, 458, 462, 468, 472, 476, 478, 482, 486, 524, 526, 528, 532, 534, 536, 538, 542, 546, 548, 562, 564, 568, 572, 574, 576, 578, 582, 584, 586, 624, 628, 632, 634, 638, 642, 648, 652, 654, 658, 672, 674, 678, 682, 684, 724, 726, 728, 732, 734, 736, 738, 742, 746, 748, 752, 754, 756, 758, 762, 764, 768, 782, 784, 786, 824, 826, 832, 834, 836, 842, 846, 852, 854, 856, 862, 864, 872, 874, 876] + - name: "four_ones_two_zeros" + in: + digits: [1, 1, 1, 1, 0, 0] + out: [100, 110] + - name: "six_high_digits" + in: + digits: [4, 5, 6, 7, 8, 9] + out: [456, 458, 468, 476, 478, 486, 496, 498, 546, 548, 564, 568, 574, 576, 578, 584, 586, 594, 596, 598, 648, 654, 658, 674, 678, 684, 694, 698, 746, 748, 754, 756, 758, 764, 768, 784, 786, 794, 796, 798, 846, 854, 856, 864, 874, 876, 894, 896, 946, 948, 954, 956, 958, 964, 968, 974, 976, 978, 984, 986] + - name: "three_fives_zero_six" + in: + digits: [0, 5, 5, 5, 6] + out: [506, 550, 556, 560, 650] + - name: "four_twos_two_fours" + in: + digits: [2, 2, 2, 2, 4, 4] + out: [222, 224, 242, 244, 422, 424, 442] + - name: "maximum_length_duplicate_one" + in: + digits: [0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9] diff --git a/tests/2001-2500/2094. finding-3-digit-even-numbers/sol.py b/tests/2001-2500/2094. finding-3-digit-even-numbers/sol.py new file mode 100644 index 00000000..f0e7f80a --- /dev/null +++ b/tests/2001-2500/2094. finding-3-digit-even-numbers/sol.py @@ -0,0 +1,18 @@ +class Solution(object): + def findEvenNumbers(self, digits): + mpp = [0]*10 + for d in digits: + mpp[d] += 1 + res = [] + for i in range(1, 10): + if mpp[i] == 0: continue + mpp[i] -= 1 + for j in range(10): + if mpp[j] == 0: continue + mpp[j] -= 1 + for k in range(0, 10, 2): + if mpp[k] == 0: continue + res.append(i*100 + j*10 + k) + mpp[j] += 1 + mpp[i] += 1 + return res \ No newline at end of file diff --git a/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/manifest.yaml b/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/manifest.yaml new file mode 100644 index 00000000..f8589f4e --- /dev/null +++ b/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/manifest.yaml @@ -0,0 +1,227 @@ +entry: + id: 2095 + title: "delete-the-middle-node-of-a-linked-list" + params: + head: + type: list_node + call: + cpp: "listNodeToArray(Solution().deleteMiddle({head}))" + rust: "ListNode::list_node_to_array(Solution::delete_middle({head}))" + python3: "list_node_to_array(Solution().deleteMiddle({head}))" + python2: "list_node_to_array(Solution().deleteMiddle({head}))" + ruby: "list_node_to_array(delete_middle({head}))" + java: "ListNode.listNodeToArray(new Solution().deleteMiddle({head}))" + csharp: "ListNode.ListNodeToArray(new Solution().DeleteMiddle({head}))" + kotlin: "listNodeToArray(Solution().deleteMiddle({head}))" + go: "listNodeToArray(deleteMiddle({head}))" + dart: "list_node_to_array(Solution().deleteMiddle({head}))" + swift: "list_node_to_array(Solution().deleteMiddle({head}))" + typescript: "listNodeToArray(deleteMiddle({head}))" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().deleteMiddle(head, {result})" + checker: | + class Checker: + def deleteMiddle(self, head, result): + if not isinstance(head, list) or not isinstance(result, list): + return False + if len(head) < 1 or len(result) != len(head) - 1: + return False + middle = len(head) // 2 + return result == head[:middle] + head[middle + 1:] + +seed: 2095 + +tests: + - name: "example_1" + in: + head: [1, 3, 4, 7, 1, 2, 6] + out: [1, 3, 4, 1, 2, 6] + - name: "example_2_even" + in: + head: [1, 2, 3, 4] + out: [1, 2, 4] + - name: "example_3_two_nodes" + in: + head: [2, 1] + out: [2] + - name: "single_node" + in: + head: [9] + out: [] + - name: "two_nodes_equal" + in: + head: [5, 5] + out: [5] + - name: "three_nodes" + in: + head: [1, 2, 3] + out: [1, 3] + - name: "four_nodes" + in: + head: [10, 20, 30, 40] + out: [10, 20, 40] + - name: "five_nodes" + in: + head: [1, 2, 3, 4, 5] + out: [1, 2, 4, 5] + - name: "six_nodes" + in: + head: [1, 2, 3, 4, 5, 6] + out: [1, 2, 3, 5, 6] + - name: "duplicate_middle_value" + in: + head: [8, 1, 8, 2, 8] + out: [8, 1, 2, 8] + - name: "duplicate_values_even" + in: + head: [7, 7, 7, 7, 7, 7] + out: [7, 7, 7, 7, 7] + - name: "minimum_values" + in: + head: [1, 1, 1, 1, 1, 1, 1] + out: [1, 1, 1, 1, 1, 1] + - name: "maximum_values" + in: + head: [100000, 100000, 100000, 100000, 100000] + out: [100000, 100000, 100000, 100000] + - name: "alternating_extremes" + in: + head: [1, 100000, 1, 100000, 1, 100000, 1, 100000] + out: [1, 100000, 1, 100000, 100000, 1, 100000] + - name: "middle_unique_even" + in: + head: [4, 4, 99, 4, 4, 4] + out: [4, 4, 99, 4, 4] + - name: "middle_unique_odd" + in: + head: [4, 4, 4, 99, 4, 4, 4] + out: [4, 4, 4, 4, 4, 4] + - name: "negative_not_allowed_boundary_pattern" + in: + head: [1, 2, 1, 2, 1, 2, 1, 2, 1] + out: [1, 2, 1, 2, 2, 1, 2, 1] + - name: "length_ten" + in: + head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: [1, 2, 3, 4, 5, 7, 8, 9, 10] + - name: "length_eleven" + in: + head: [11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 122] + out: [11, 22, 33, 44, 55, 77, 88, 99, 111, 122] + - name: "repeated_runs" + in: + head: [1, 1, 2, 2, 2, 3, 3, 4] + out: [1, 1, 2, 2, 3, 3, 4] + - name: "large_value_at_middle" + in: + head: [1, 2, 3, 4, 100000, 6, 7, 8, 9] + out: [1, 2, 3, 4, 6, 7, 8, 9] + - name: "head_large_tail_small" + in: + head: [100000, 99999, 99998, 99997, 1, 2] + out: [100000, 99999, 99998, 1, 2] + - name: "long_odd_static" + in: + head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + out: [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15] + - name: "long_even_static" + in: + head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] + out: [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16] + - name: "length_seven_descending" + in: + head: [7, 6, 5, 4, 3, 2, 1] + out: [7, 6, 5, 3, 2, 1] + - name: "length_eight_descending" + in: + head: [8, 7, 6, 5, 4, 3, 2, 1] + out: [8, 7, 6, 5, 3, 2, 1] + - name: "length_twelve" + in: + head: [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144] + out: [12, 24, 36, 48, 60, 72, 96, 108, 120, 132, 144] + - name: "all_max_except_middle" + in: + head: [100000, 100000, 1, 100000, 100000, 100000, 100000] + out: [100000, 100000, 1, 100000, 100000, 100000] + - name: "same_value_around_middle" + in: + head: [3, 9, 9, 9, 3, 3, 3, 9, 3] + out: [3, 9, 9, 9, 3, 3, 9, 3] + - name: "alternating_length_fourteen" + in: + head: [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] + out: [1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2] + - name: "generated_small_mixed" + seed: 101 + in: + head: + gen: "array" + len: + gen: "int" + min: 1 + max: 25 + of: + gen: "int" + min: 1 + max: 100000 + elemType: "int" + - name: "generated_small_duplicates" + seed: 102 + in: + head: + gen: "array" + len: + gen: "int" + min: 1 + max: 40 + of: + gen: "int" + min: 1 + max: 3 + elemType: "int" + - name: "generated_medium" + seed: 103 + in: + head: + gen: "array" + len: + gen: "int" + min: 100 + max: 500 + of: + gen: "int" + min: 1 + max: 100000 + elemType: "int" + - name: "generated_large_odd" + seed: 104 + in: + head: + gen: "array" + len: 99999 + of: + gen: "int" + min: 1 + max: 100000 + elemType: "int" + - name: "generated_large_even" + seed: 105 + in: + head: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 100000 + elemType: "int" diff --git a/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/sol.py b/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/sol.py new file mode 100644 index 00000000..dfcf3fcc --- /dev/null +++ b/tests/2001-2500/2095. delete-the-middle-node-of-a-linked-list/sol.py @@ -0,0 +1,16 @@ +class Solution: + def deleteMiddle(self, head: ListNode) -> ListNode: + if not head or not head.next: + return None + + prev, slow, fast = None, head, head + + while fast and fast.next: + prev = slow + slow = slow.next + fast = fast.next.next + + if prev: + prev.next = slow.next # Remove middle node + + return head \ No newline at end of file diff --git a/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/manifest.yaml b/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/manifest.yaml new file mode 100644 index 00000000..1c379bcf --- /dev/null +++ b/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/manifest.yaml @@ -0,0 +1,286 @@ +entry: + id: 2096 + title: "step-by-step-directions-from-a-binary-tree-node-to-another" + params: + root: + type: tree_node + start: + type: int + dest: + type: int + call: + cpp: "Solution().getDirections({root}, {start}, {dest})" + rust: "Solution::get_directions({root}, {start}, {dest})" + python3: "Solution().getDirections({root}, {start}, {dest})" + python2: "Solution().getDirections({root}, {start}, {dest})" + ruby: "get_directions({root}, {start}, {dest})" + java: "new Solution().getDirections({root}, {start}, {dest})" + csharp: "new Solution().GetDirections({root}, {start}, {dest})" + kotlin: "Solution().getDirections({root}, {start}, {dest})" + go: "getDirections({root}, {start}, {dest})" + dart: "Solution().getDirections({root}, {start}, {dest})" + swift: "Solution().getDirections({root}, {start}, {dest})" + typescript: "getDirections({root}, {start}, {dest})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().getDirections(root, start, dest, {result})" + checker: | + class Checker: + def getDirections(self, root, start, dest, result): + if not isinstance(result, str) or any(ch not in 'LRU' for ch in result): + return False + parent = {} + move = {} + stack = [root] + while stack: + node = stack.pop() + if node is None: + continue + if node.left is not None: + parent[node.left.val] = node.val + move[node.left.val] = 'L' + stack.append(node.left) + if node.right is not None: + parent[node.right.val] = node.val + move[node.right.val] = 'R' + stack.append(node.right) + paths = {} + node = start + paths[node] = '' + while node in parent: + paths[parent[node]] = paths[node] + 'U' + node = parent[node] + node = dest + down = '' + while node not in paths: + down = move[node] + down + node = parent[node] + return result == paths[node] + down + +seed: 2096001 + +tests: + - name: "example_1" + in: + root: [5, 1, 2, 3, null, 6, 4] + start: 3 + dest: 6 + out: "UURL" + - name: "example_2" + in: + root: [2, 1] + start: 2 + dest: 1 + out: "L" + - name: "root_to_left" + in: + root: [1, 2, 3] + start: 1 + dest: 2 + out: "L" + - name: "root_to_right" + in: + root: [1, 2, 3] + start: 1 + dest: 3 + out: "R" + - name: "left_to_root" + in: + root: [1, 2, 3] + start: 2 + dest: 1 + out: "U" + - name: "right_to_root" + in: + root: [1, 2, 3] + start: 3 + dest: 1 + out: "U" + - name: "left_to_right_siblings" + in: + root: [1, 2, 3] + start: 2 + dest: 3 + out: "UR" + - name: "right_to_left_siblings" + in: + root: [1, 2, 3] + start: 3 + dest: 2 + out: "UL" + - name: "left_chain_down" + in: + root: [1, 2, null, 4, null, 5, null, 7] + start: 1 + dest: 7 + out: "LLLL" + - name: "left_chain_up" + in: + root: [1, 2, null, 4, null, 5, null, 7] + start: 7 + dest: 1 + out: "UUUU" + - name: "right_chain_down" + in: + root: [1, null, 2, null, 4, null, 8] + start: 1 + dest: 8 + out: "RRR" + - name: "right_chain_up" + in: + root: [1, null, 2, null, 4, null, 8] + start: 8 + dest: 1 + out: "UUU" + - name: "zigzag_left_right" + in: + root: [10, 4, null, null, 7, null, 9] + start: 10 + dest: 9 + out: "LRR" + - name: "zigzag_right_left" + in: + root: [10, null, 20, 15, null, 12] + start: 10 + dest: 12 + out: "RLL" + - name: "deep_branch_to_branch" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 1 + dest: 15 + out: "UUURRR" + - name: "deep_branch_reverse" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 15 + dest: 1 + out: "UUULLL" + - name: "same_parent_left_to_right" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 5 + dest: 7 + out: "UR" + - name: "same_parent_right_to_left" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 7 + dest: 5 + out: "UL" + - name: "ancestor_to_grandchild" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 4 + dest: 7 + out: "RR" + - name: "grandchild_to_ancestor" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 7 + dest: 4 + out: "UU" + - name: "right_subtree_internal" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 9 + dest: 14 + out: "UUR" + - name: "left_subtree_internal" + in: + root: [8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15] + start: 2 + dest: 6 + out: "UR" + - name: "nonconsecutive_labels" + in: + root: [100, 20, 300, 10, 50, null, 400, null, 15] + start: 15 + dest: 400 + out: "UUURR" + - name: "label_boundary_low" + in: + root: [100000, 1, 99999, 2, null, null, 99998] + start: 1 + dest: 99998 + out: "URR" + - name: "label_boundary_high" + in: + root: [100000, 1, 99999, 2, null, null, 99998] + start: 100000 + dest: 99998 + out: "RR" + - name: "sparse_tree_left" + in: + root: [50, 20, 80, null, 30, 60, null, 25] + start: 25 + dest: 60 + out: "UUURL" + - name: "sparse_tree_right" + in: + root: [50, 20, 80, null, 30, 60, null, 25] + start: 60 + dest: 25 + out: "UULRL" + - name: "full_height_three" + in: + root: [1, 2, 3, 4, 5, 6, 7] + start: 4 + dest: 7 + out: "UURR" + - name: "full_height_three_reverse" + in: + root: [1, 2, 3, 4, 5, 6, 7] + start: 7 + dest: 4 + out: "UULL" + - name: "full_height_four_left_to_right" + in: + root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + start: 8 + dest: 15 + out: "UUURRR" + - name: "full_height_four_right_to_left" + in: + root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + start: 15 + dest: 8 + out: "UUULLL" + - name: "full_height_four_cross" + in: + root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + start: 10 + dest: 14 + out: "UUURRL" + - name: "full_height_four_ancestor" + in: + root: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + start: 2 + dest: 9 + out: "LR" + - name: "larger_balanced_cross" + in: + root: [16, 8, 24, 4, 12, 20, 28, 2, 6, 10, 14, 18, 22, 26, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] + start: 1 + dest: 31 + out: "UUUURRRR" + - name: "larger_balanced_inner" + in: + root: [16, 8, 24, 4, 12, 20, 28, 2, 6, 10, 14, 18, 22, 26, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] + start: 11 + dest: 23 + out: "UUUURLRR" + - name: "larger_balanced_reverse" + in: + root: [16, 8, 24, 4, 12, 20, 28, 2, 6, 10, 14, 18, 22, 26, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] + start: 31 + dest: 1 + out: "UUUULLLL" diff --git a/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/sol.py b/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/sol.py new file mode 100644 index 00000000..b47a52b0 --- /dev/null +++ b/tests/2001-2500/2096. step-by-step-directions-from-a-binary-tree-node-to-another/sol.py @@ -0,0 +1,48 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def getDirections(self, root: Optional[TreeNode], start: int, dest: int) -> str: + graph = defaultdict(list) + + def build_graph(root): + if not root: + return + + if root.left: + u, v = root.val, root.left.val + graph[u].append((v, 'L')) + graph[v].append((u, 'U')) + + if root.right: + u, v = root.val, root.right.val + graph[u].append((v, 'R')) + graph[v].append((u, 'U')) + + build_graph(root.left) + build_graph(root.right) + + build_graph(root) + + temp = [] + def build_path(node, prev): + if node == dest: + return True + + for adj_node, move in graph[node]: + if adj_node == prev: + continue + temp.append(move) + if build_path(adj_node, node): + return True + temp.pop() + + return False + + if build_path(start, -1): + print("Done") + + return ''.join(temp) \ No newline at end of file diff --git a/tests/2001-2500/2097. valid-arrangement-of-pairs/manifest.yaml b/tests/2001-2500/2097. valid-arrangement-of-pairs/manifest.yaml new file mode 100644 index 00000000..09762937 --- /dev/null +++ b/tests/2001-2500/2097. valid-arrangement-of-pairs/manifest.yaml @@ -0,0 +1,432 @@ +entry: + id: 2097 + title: "valid-arrangement-of-pairs" + params: + pairs: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().validArrangement({pairs})" + rust: "Solution::valid_arrangement({pairs})" + python3: "Solution().validArrangement({pairs})" + python2: "Solution().validArrangement({pairs})" + ruby: "valid_arrangement({pairs})" + java: "new Solution().validArrangement({pairs})" + csharp: "new Solution().ValidArrangement({pairs})" + kotlin: "Solution().validArrangement({pairs})" + go: "validArrangement({pairs})" + dart: "Solution().validArrangement({pairs})" + swift: "Solution().validArrangement({pairs})" + typescript: "validArrangement({pairs})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().validArrangement(pairs, {result})" + checker: | + class Checker: + def validArrangement(self, pairs, result): + if not isinstance(result, list) or len(result) != len(pairs): + return False + counts = {} + for edge in pairs: + if not isinstance(edge, list) or len(edge) != 2: + return False + key = (edge[0], edge[1]) + counts[key] = counts.get(key, 0) + 1 + for i, edge in enumerate(result): + if not isinstance(edge, list) or len(edge) != 2: + return False + key = (edge[0], edge[1]) + if counts.get(key, 0) == 0: + return False + counts[key] -= 1 + if i and result[i - 1][1] != edge[0]: + return False + return all(value == 0 for value in counts.values()) + +seed: 2097 + +tests: + - name: "example_one" + in: + pairs: + - [5, 1] + - [4, 5] + - [11, 9] + - [9, 4] + - name: "example_two_cycle" + in: + pairs: + - [1, 3] + - [3, 2] + - [2, 1] + - name: "example_three_branch" + in: + pairs: + - [1, 2] + - [1, 3] + - [2, 1] + - name: "single_edge_zero" + in: + pairs: + - [0, 1000000000] + - name: "single_edge_max_reversed" + in: + pairs: + - [1000000000, 0] + - name: "two_edge_chain" + in: + pairs: + - [7, 8] + - [8, 9] + - name: "two_edge_cycle" + in: + pairs: + - [42, 17] + - [17, 42] + - name: "three_edge_chain" + in: + pairs: + - [0, 1] + - [1, 2] + - [2, 3] + - name: "self_returning_cycle_without_self_edge" + in: + pairs: + - [9, 4] + - [4, 9] + - [9, 8] + - [8, 9] + - name: "star_out_and_return" + in: + pairs: + - [10, 1] + - [1, 10] + - [10, 2] + - [2, 10] + - [10, 3] + - [3, 10] + - name: "branching_open_trail" + in: + pairs: + - [5, 1] + - [5, 2] + - [1, 5] + - [2, 3] + - [3, 5] + - name: "nested_branching" + in: + pairs: + - [0, 2] + - [0, 1] + - [2, 0] + - [1, 3] + - [3, 0] + - [0, 4] + - [4, 0] + - name: "long_chain_reversed_input" + in: + pairs: + - [5, 6] + - [4, 5] + - [3, 4] + - [2, 3] + - [1, 2] + - [0, 1] + - name: "cycle_reversed_input" + in: + pairs: + - [30, 10] + - [20, 30] + - [10, 20] + - [40, 10] + - [10, 40] + - name: "duplicate_endpoints_distinct_edges" + in: + pairs: + - [8, 1] + - [1, 8] + - [8, 2] + - [2, 8] + - [8, 3] + - [3, 8] + - [8, 4] + - [4, 8] + - name: "negative_like_unsigned_boundary" + in: + pairs: + - [0, 999999999] + - [999999999, 1] + - [1, 1000000000] + - name: "large_labels_cycle" + in: + pairs: + - [1000000000, 999999999] + - [999999999, 500000000] + - [500000000, 0] + - [0, 1000000000] + - name: "two_cycles_joined_at_vertex" + in: + pairs: + - [1, 2] + - [2, 1] + - [1, 3] + - [3, 1] + - [1, 4] + - [4, 1] + - name: "four_way_open_branch" + in: + pairs: + - [100, 10] + - [100, 20] + - [100, 30] + - [10, 100] + - [20, 100] + - [30, 40] + - [40, 100] + - name: "interleaved_input_order" + in: + pairs: + - [2, 3] + - [0, 1] + - [4, 5] + - [1, 2] + - [3, 4] + - name: "dense_small_cycle" + in: + pairs: + - [0, 1] + - [1, 0] + - [0, 2] + - [2, 0] + - [0, 3] + - [3, 0] + - [0, 4] + - [4, 0] + - [0, 5] + - [5, 0] + - name: "deep_detour" + in: + pairs: + - [50, 1] + - [1, 2] + - [2, 3] + - [3, 50] + - [50, 4] + - [4, 5] + - [5, 50] + - name: "alternating_labels" + in: + pairs: + - [6, 100] + - [100, 7] + - [7, 200] + - [200, 8] + - [8, 300] + - [300, 6] + - name: "open_with_late_start" + in: + pairs: + - [9, 10] + - [10, 11] + - [11, 12] + - [12, 13] + - [8, 9] + - name: "many_detours" + in: + pairs: + - [7, 1] + - [1, 7] + - [7, 2] + - [2, 3] + - [3, 7] + - [7, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - name: "zero_hub" + in: + pairs: + - [0, 2] + - [2, 0] + - [0, 4] + - [4, 0] + - [0, 6] + - [6, 0] + - [0, 8] + - [8, 0] + - name: "maximum_hub" + in: + pairs: + - [1000000000, 1] + - [1, 1000000000] + - [1000000000, 2] + - [2, 1000000000] + - [1000000000, 3] + - [3, 1000000000] + - name: "mixed_scale_cycle" + in: + pairs: + - [0, 999] + - [999, 1000000000] + - [1000000000, 17] + - [17, 0] + - [0, 500000000] + - [500000000, 0] + - name: "ten_edge_open" + in: + pairs: + - [10, 11] + - [11, 12] + - [12, 10] + - [10, 13] + - [13, 14] + - [14, 10] + - [10, 15] + - [15, 16] + - [16, 10] + - [10, 17] + - name: "wide_euler_cycle" + in: + pairs: + - [500, 1] + - [1, 500] + - [500, 2] + - [2, 500] + - [500, 3] + - [3, 500] + - [500, 4] + - [4, 500] + - [500, 5] + - [5, 500] + - name: "crossed_open_edges" + in: + pairs: + - [20, 1] + - [20, 2] + - [1, 20] + - [2, 3] + - [3, 4] + - [4, 20] + - [20, 5] + - name: "large_chain_50" + in: + pairs: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + - [8, 9] + - [9, 10] + - [10, 11] + - [11, 12] + - [12, 13] + - [13, 14] + - [14, 15] + - [15, 16] + - [16, 17] + - [17, 18] + - [18, 19] + - [19, 20] + - [20, 21] + - [21, 22] + - [22, 23] + - [23, 24] + - [24, 25] + - [25, 26] + - [26, 27] + - [27, 28] + - [28, 29] + - [29, 30] + - [30, 31] + - [31, 32] + - [32, 33] + - [33, 34] + - [34, 35] + - [35, 36] + - [36, 37] + - [37, 38] + - [38, 39] + - [39, 40] + - [40, 41] + - [41, 42] + - [42, 43] + - [43, 44] + - [44, 45] + - [45, 46] + - [46, 47] + - [47, 48] + - [48, 49] + - [49, 50] + - name: "stress_like_long_cycle" + in: + pairs: + - [1000000000, 999999999] + - [999999999, 999999998] + - [999999998, 999999997] + - [999999997, 999999996] + - [999999996, 999999995] + - [999999995, 999999994] + - [999999994, 999999993] + - [999999993, 999999992] + - [999999992, 999999991] + - [999999991, 999999990] + - [999999990, 999999989] + - [999999989, 999999988] + - [999999988, 999999987] + - [999999987, 999999986] + - [999999986, 999999985] + - [999999985, 999999984] + - [999999984, 999999983] + - [999999983, 999999982] + - [999999982, 999999981] + - [999999981, 1000000000] + - name: "stress_like_branching_cycle" + in: + pairs: + - [700000000, 1] + - [1, 700000000] + - [700000000, 2] + - [2, 700000000] + - [700000000, 3] + - [3, 700000000] + - [700000000, 4] + - [4, 700000000] + - [700000000, 5] + - [5, 700000000] + - [700000000, 6] + - [6, 700000000] + - [700000000, 7] + - [7, 700000000] + - [700000000, 8] + - [8, 700000000] + - [700000000, 9] + - [9, 700000000] + - [700000000, 10] + - [10, 700000000] + - name: "asymmetric_eulerian_cycle" + in: + pairs: + - [77, 12] + - [12, 77] + - [77, 13] + - [13, 14] + - [14, 77] + - [77, 15] + - [15, 16] + - [16, 17] + - [17, 77] diff --git a/tests/2001-2500/2097. valid-arrangement-of-pairs/sol.py b/tests/2001-2500/2097. valid-arrangement-of-pairs/sol.py new file mode 100644 index 00000000..0677011f --- /dev/null +++ b/tests/2001-2500/2097. valid-arrangement-of-pairs/sol.py @@ -0,0 +1,35 @@ +import collections + +class Solution: + def validArrangement(self, pairs: List[List[int]]) -> List[List[int]]: + # 1. Coordinate Mapping (Numerical State-Space) + adj = collections.defaultdict(list) + in_degree = collections.defaultdict(int) + out_degree = collections.defaultdict(int) + + for u, v in pairs: + adj[u].append(v) + out_degree[u] += 1 + in_degree[v] += 1 + + # 2. Find the Root (The Source of the Flow) + # In a valid arrangement, the start node has out_degree = in_degree + 1 + start_node = pairs[0][0] + for node in out_degree: + if out_degree[node] > in_degree[node]: + start_node = node + break + + # 3. Draining the Matrix (Hierholzer's via Spanning Tree logic) + res = [] + stack = [start_node] + + while stack: + while adj[stack[-1]]: + # We drain the 'out-degree' flow + stack.append(adj[stack[-1]].pop()) + res.append(stack.pop()) + + # 4. Reconstructing the Pairs + res.reverse() + return [[res[i], res[i+1]] for i in range(len(res) - 1)] \ No newline at end of file diff --git a/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/manifest.yaml b/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/manifest.yaml new file mode 100644 index 00000000..46f692d1 --- /dev/null +++ b/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/manifest.yaml @@ -0,0 +1,269 @@ +entry: + id: 2099 + title: "find-subsequence-of-length-k-with-the-largest-sum" + params: + nums: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().maxSubsequence({nums}, {k})" + rust: "Solution::max_subsequence({nums}, {k})" + python3: "Solution().maxSubsequence({nums}, {k})" + python2: "Solution().maxSubsequence({nums}, {k})" + ruby: "max_subsequence({nums}, {k})" + java: "new Solution().maxSubsequence({nums}, {k})" + csharp: "new Solution().MaxSubsequence({nums}, {k})" + kotlin: "Solution().maxSubsequence({nums}, {k})" + go: "maxSubsequence({nums}, {k})" + dart: "Solution().maxSubsequence({nums}, {k})" + swift: "Solution().maxSubsequence({nums}, {k})" + typescript: "maxSubsequence({nums}, {k})" + +judge: + type: exact + +limits: + time_ms: 2000 + memory_mb: 256 + +oracle: + python3: + call: "Checker().maxSubsequence(nums, k, {result})" + checker: | + class Checker: + def maxSubsequence(self, nums, k, result): + if not isinstance(result, list) or len(result) != k: + return False + need = sorted(nums, reverse=True)[:k] + if sum(result) != sum(need): + return False + pos = 0 + for value in result: + while pos < len(nums) and nums[pos] != value: + pos += 1 + if pos == len(nums): + return False + pos += 1 + return True + +seed: 2099 + +tests: + - name: "example 1" + in: + nums: [2, 1, 3, 3] + k: 2 + out: [3, 3] + - name: "example 2" + in: + nums: [-1, -2, 3, 4] + k: 3 + out: [-1, 3, 4] + - name: "example 3 tie" + in: + nums: [3, 4, 3, 3] + k: 2 + - name: "single positive" + in: + nums: [7] + k: 1 + out: [7] + - name: "single negative" + in: + nums: [-100000] + k: 1 + out: [-100000] + - name: "take all preserves order" + in: + nums: [5, -2, 8, 0] + k: 4 + out: [5, -2, 8, 0] + - name: "all negative" + in: + nums: [-5, -1, -9, -2] + k: 2 + - name: "all equal" + in: + nums: [4, 4, 4, 4, 4] + k: 3 + out: [4, 4, 4] + - name: "duplicate cutoff" + in: + nums: [9, 1, 9, 8, 9, 2] + k: 3 + - name: "zero cutoff" + in: + nums: [0, -1, 0, 2, -2] + k: 3 + - name: "large bounds" + in: + nums: [-100000, 100000, 99999, -99999] + k: 2 + out: [100000, 99999] + - name: "alternating extremes" + in: + nums: [100000, -100000, 100000, -100000, 99999] + k: 3 + - name: "best values at ends" + in: + nums: [10, -4, -3, 8] + k: 2 + out: [10, 8] + - name: "best values separated" + in: + nums: [-8, 6, -7, 5, -6, 4] + k: 3 + out: [6, 5, 4] + - name: "k one" + in: + nums: [-3, 12, 4, 12, 1] + k: 1 + - name: "k n minus one" + in: + nums: [1, 100, 2, 3, 4] + k: 4 + - name: "negative duplicate values" + in: + nums: [-2, -2, -1, -2, -1] + k: 3 + - name: "mixed zeroes" + in: + nums: [0, 0, -1, 0, 1, -1] + k: 4 + - name: "descending" + in: + nums: [9, 8, 7, 6, 5, 4] + k: 3 + out: [9, 8, 7] + - name: "ascending" + in: + nums: [1, 2, 3, 4, 5, 6] + k: 3 + out: [4, 5, 6] + - name: "repeated maximum" + in: + nums: [5, 1, 5, 2, 5, 3, 5] + k: 4 + - name: "near max integers" + in: + nums: [99998, -99998, 99997, -99997, 99996, -99996] + k: 3 + - name: "minimum length two" + in: + nums: [-4, -3] + k: 1 + out: [-3] + - name: "interleaved duplicates" + in: + nums: [2, 9, 2, 9, 2, 9, 1] + k: 2 + - name: "many tied cutoff" + in: + nums: [6, 1, 6, 6, 2, 6, 3, 6] + k: 5 + - name: "negative to positive" + in: + nums: [-10, -9, -8, 7, 6, 5] + k: 4 + - name: "large sum safe" + in: + nums: [100000, 100000, 100000, 100000, 100000] + k: 5 + out: [100000, 100000, 100000, 100000, 100000] + - name: "late optimum" + in: + nums: [-1, -2, -3, -4, 50, 40, 30] + k: 2 + out: [50, 40] + - name: "early optimum" + in: + nums: [50, 40, 30, -1, -2, -3] + k: 2 + out: [50, 40] + - name: "value order differs from index order" + in: + nums: [8, 1, 7, 2, 6, 3] + k: 4 + out: [8, 7, 6, 3] + - name: "all selected tied" + in: + nums: [-7, -7, -7] + k: 2 + out: [-7, -7] + - name: "mixed repeated negatives" + in: + nums: [-1, -5, -1, -3, -1, -2] + k: 4 + - name: "gen small mixed" + in: + nums: + gen: array + len: 20 + of: + gen: int + min: -100000 + max: 100000 + elemType: int + k: + gen: int + min: 1 + max: 20 + - name: "gen medium mixed" + in: + nums: + gen: array + len: 100 + of: + gen: int + min: -100000 + max: 100000 + elemType: int + k: + gen: int + min: 1 + max: 100 + - name: "gen all negative" + in: + nums: + gen: array + len: 75 + of: + gen: int + min: -100000 + max: -1 + elemType: int + k: + gen: int + min: 1 + max: 75 + - name: "gen large maximum size" + in: + nums: + gen: array + len: 1000 + of: + gen: int + min: -100000 + max: 100000 + elemType: int + k: + gen: int + min: 1 + max: 1000 + - name: "gen large nonpositive" + in: + nums: + gen: array + len: 1000 + of: + gen: int + min: -100000 + max: 0 + elemType: int + k: + gen: int + min: 1 + max: 1000 diff --git a/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/sol.py b/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/sol.py new file mode 100644 index 00000000..f3ae0a38 --- /dev/null +++ b/tests/2001-2500/2099. find-subsequence-of-length-k-with-the-largest-sum/sol.py @@ -0,0 +1,15 @@ +from typing import List + +class Solution: + def maxSubsequence(self, nums: List[int], k: int) -> List[int]: + # Pair with indices + nums_with_indices = [(num, i) for i, num in enumerate(nums)] + + # Sort by value descending + nums_with_indices.sort(key=lambda x: -x[0]) + + # Take top k and sort by original index + top_k = sorted(nums_with_indices[:k], key=lambda x: x[1]) + + # Extract values + return [num for num, _ in top_k] \ No newline at end of file diff --git a/tests/2001-2500/2100. find-good-days-to-rob-the-bank/manifest.yaml b/tests/2001-2500/2100. find-good-days-to-rob-the-bank/manifest.yaml new file mode 100644 index 00000000..e28b5f72 --- /dev/null +++ b/tests/2001-2500/2100. find-good-days-to-rob-the-bank/manifest.yaml @@ -0,0 +1,296 @@ +entry: + id: 2100 + title: "find-good-days-to-rob-the-bank" + params: + security: + type: array + items: + type: int + time: + type: int + call: + cpp: "Solution().goodDaysToRobBank({security}, {time})" + rust: "Solution::good_days_to_rob_bank({security}, {time})" + python3: "Solution().goodDaysToRobBank({security}, {time})" + python2: "Solution().goodDaysToRobBank({security}, {time})" + ruby: "good_days_to_rob_bank({security}, {time})" + java: "new Solution().goodDaysToRobBank({security}, {time})" + csharp: "new Solution().GoodDaysToRobBank({security}, {time})" + kotlin: "Solution().goodDaysToRobBank({security}, {time})" + go: "goodDaysToRobBank({security}, {time})" + dart: "Solution().goodDaysToRobBank({security}, {time})" + swift: "Solution().goodDaysToRobBank({security}, {time})" + typescript: "goodDaysToRobBank({security}, {time})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().goodDaysToRobBank(security, time, {result})" + checker: | + class Checker: + def goodDaysToRobBank(self, security, time, result): + if not isinstance(result, list) or any(not isinstance(x, int) for x in result): + return False + if len(result) != len(set(result)): + return False + expected = [] + n = len(security) + for i in range(n): + if i < time or i + time >= n: + continue + if all(security[j] >= security[j + 1] for j in range(i - time, i)) and all(security[j] <= security[j + 1] for j in range(i, i + time)): + expected.append(i) + return sorted(result) == expected + +seed: 2100 + +tests: + - name: "example_plateau" + in: + security: [5, 3, 3, 3, 5, 6, 2] + time: 2 + out: [2, 3] + - name: "example_time_zero" + in: + security: [1, 1, 1, 1, 1] + time: 0 + out: [0, 1, 2, 3, 4] + - name: "example_increasing" + in: + security: [1, 2, 3, 4, 5, 6] + time: 2 + out: [] + - name: "single_zero_time" + in: + security: [7] + time: 0 + out: [0] + - name: "single_positive_time" + in: + security: [7] + time: 1 + out: [] + - name: "two_equal_time_zero" + in: + security: [4, 9] + time: 0 + out: [0, 1] + - name: "two_time_one" + in: + security: [4, 4] + time: 1 + out: [] + - name: "time_exceeds_length" + in: + security: [1, 2, 1] + time: 4 + out: [] + - name: "all_decreasing" + in: + security: [9, 8, 7, 6, 5, 4] + time: 2 + out: [] + - name: "all_constant" + in: + security: [3, 3, 3, 3, 3, 3, 3] + time: 2 + out: [2, 3, 4] + - name: "valley_single" + in: + security: [5, 4, 3, 2, 1, 2, 3, 4, 5] + time: 4 + out: [4] + - name: "valley_two" + in: + security: [5, 4, 2, 2, 3, 5] + time: 2 + out: [2, 3] + - name: "peak_rejected" + in: + security: [1, 2, 3, 2, 1] + time: 1 + out: [] + - name: "edge_valley" + in: + security: [5, 4, 3, 4, 5] + time: 1 + out: [2] + - name: "one_step_valleys" + in: + security: [3, 2, 3, 2, 3] + time: 1 + out: [1, 3] + - name: "alternating_strict" + in: + security: [0, 10, 0, 10, 0, 10, 0] + time: 1 + out: [2, 4] + - name: "negative_not_allowed_boundary_values" + in: + security: [0, 0, 1, 0, 0] + time: 1 + out: [1, 3] + - name: "zero_plateau_valley" + in: + security: [8, 5, 0, 0, 0, 5, 8] + time: 3 + out: [3] + - name: "two_disjoint_valleys" + in: + security: [6, 5, 4, 5, 6, 9, 8, 7, 8, 9] + time: 2 + out: [2, 7] + - name: "flat_before_rise" + in: + security: [4, 4, 4, 5, 6] + time: 1 + out: [1, 2] + - name: "flat_after_fall" + in: + security: [6, 5, 4, 4, 4] + time: 1 + out: [2, 3] + - name: "time_one_mixed" + in: + security: [5, 4, 4, 5, 3, 3, 4] + time: 1 + out: [1, 2, 4, 5] + - name: "time_two_mixed" + in: + security: [7, 6, 6, 5, 6, 6, 7] + time: 2 + out: [3] + - name: "boundary_only_left" + in: + security: [4, 3, 2, 3] + time: 1 + out: [2] + - name: "boundary_only_right" + in: + security: [3, 2, 3, 4] + time: 1 + out: [1] + - name: "large_values" + in: + security: [100000, 99999, 99999, 100000] + time: 1 + out: [1, 2] + - name: "all_zero" + in: + security: [0, 0, 0, 0, 0, 0, 0, 0] + time: 3 + out: [3, 4] + - name: "long_flat_center" + in: + security: [9, 8, 8, 8, 8, 9, 9, 10] + time: 2 + out: [2, 3, 4] + - name: "strict_valley_time_two" + in: + security: [10, 8, 6, 4, 6, 8, 10] + time: 2 + out: [3] + - name: "no_room_exact" + in: + security: [5, 4, 3, 4, 5] + time: 3 + out: [] + - name: "many_equal_runs" + in: + security: [5, 5, 4, 4, 4, 5, 5, 4, 4, 5] + time: 2 + out: [2, 3, 4, 7] + - name: "generated_small" + seed: 301 + in: + security: + gen: "array" + len: + gen: "int" + min: 1 + max: 40 + of: + gen: "int" + min: 0 + max: 20 + distinct: false + sorted: false + elemType: "int" + time: + gen: "int" + min: 0 + max: 40 + - name: "generated_medium" + seed: 302 + in: + security: + gen: "array" + len: + gen: "int" + min: 100 + max: 500 + of: + gen: "int" + min: 0 + max: 100000 + distinct: false + sorted: false + elemType: "int" + time: + gen: "int" + min: 0 + max: 500 + - name: "generated_large_random" + seed: 303 + in: + security: + gen: "array" + len: 80000 + of: + gen: "int" + min: 0 + max: 100000 + distinct: false + sorted: false + elemType: "int" + time: + gen: "int" + min: 0 + max: 100000 + - name: "generated_large_constant_range" + seed: 304 + in: + security: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 3 + distinct: false + sorted: false + elemType: "int" + time: + gen: "int" + min: 0 + max: 100000 + - name: "generated_max_length" + seed: 305 + in: + security: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 100000 + distinct: false + sorted: false + elemType: "int" + time: 0 diff --git a/tests/2001-2500/2100. find-good-days-to-rob-the-bank/sol.py b/tests/2001-2500/2100. find-good-days-to-rob-the-bank/sol.py new file mode 100644 index 00000000..86f3cc16 --- /dev/null +++ b/tests/2001-2500/2100. find-good-days-to-rob-the-bank/sol.py @@ -0,0 +1,8 @@ +from itertools import accumulate, pairwise + + +class Solution: + def goodDaysToRobBank(self, a: List[int], t: int) -> List[int]: + f = lambda a:[*accumulate(pairwise(a),lambda q,p:(q+1)*ge(*p),initial=0)] + l, r = f(a), f(a[::-1])[::-1] + return [i for i in range(len(a)) if l[i]>=t<=r[i]] diff --git a/tests/2001-2500/2101. detonate-the-maximum-bombs/manifest.yaml b/tests/2001-2500/2101. detonate-the-maximum-bombs/manifest.yaml new file mode 100644 index 00000000..62e64307 --- /dev/null +++ b/tests/2001-2500/2101. detonate-the-maximum-bombs/manifest.yaml @@ -0,0 +1,362 @@ +entry: + id: 2101 + title: "detonate-the-maximum-bombs" + params: + bombs: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().maximumDetonation({bombs})" + rust: "Solution::maximum_detonation({bombs})" + python3: "Solution().maximumDetonation({bombs})" + python2: "Solution().maximumDetonation({bombs})" + ruby: "maximum_detonation({bombs})" + java: "new Solution().maximumDetonation({bombs})" + csharp: "new Solution().MaximumDetonation({bombs})" + kotlin: "Solution().maximumDetonation({bombs})" + go: "maximumDetonation({bombs})" + dart: "Solution().maximumDetonation({bombs})" + swift: "Solution().maximumDetonation({bombs})" + typescript: "maximumDetonation({bombs})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().maximumDetonation(bombs, {result})" + checker: | + class Checker: + def maximumDetonation(self, bombs, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(bombs) + if n < 1 or result < 1 or result > n: + return False + graph = [[] for _ in range(n)] + for i, (x1, y1, r1) in enumerate(bombs): + for j, (x2, y2, r2) in enumerate(bombs): + if i != j and (x2 - x1) ** 2 + (y2 - y1) ** 2 <= r1 ** 2: + graph[i].append(j) + best = 0 + for start in range(n): + seen = {start} + stack = [start] + while stack: + for nxt in graph[stack.pop()]: + if nxt not in seen: + seen.add(nxt) + stack.append(nxt) + best = max(best, len(seen)) + return result == best + +seed: 2101 + +tests: + - name: "example_1" + in: + bombs: + - [2, 1, 3] + - [6, 1, 4] + out: 2 + - name: "example_2" + in: + bombs: + - [1, 1, 5] + - [10, 10, 5] + out: 1 + - name: "example_3" + in: + bombs: + - [1, 2, 3] + - [2, 3, 1] + - [3, 4, 2] + - [4, 5, 3] + - [5, 6, 4] + out: 5 + - name: "single_bomb" + in: + bombs: + - [1, 1, 1] + out: 1 + - name: "identical_locations" + in: + bombs: + - [5, 5, 1] + - [5, 5, 1] + - [5, 5, 1] + - [5, 5, 1] + out: 4 + - name: "touching_boundary" + in: + bombs: + - [1, 1, 2] + - [3, 1, 1] + out: 2 + - name: "just_outside_boundary" + in: + bombs: + - [1, 1, 1] + - [3, 1, 1] + out: 1 + - name: "one_way_chain" + in: + bombs: + - [1, 1, 2] + - [3, 1, 2] + - [7, 1, 2] + out: 2 + - name: "reverse_chain_best_end" + in: + bombs: + - [1, 1, 1] + - [2, 1, 2] + - [4, 1, 3] + out: 3 + - name: "disjoint_three" + in: + bombs: + - [1, 1, 1] + - [10, 10, 1] + - [100, 100, 1] + out: 1 + - name: "two_cycle" + in: + bombs: + - [1, 1, 3] + - [3, 1, 3] + out: 2 + - name: "cycle_with_tail" + in: + bombs: + - [1, 1, 3] + - [3, 1, 3] + - [5, 1, 1] + out: 3 + - name: "large_coordinates_near" + in: + bombs: + - [100000, 100000, 100000] + - [1, 100000, 99999] + - [100000, 1, 99999] + out: 3 + - name: "large_coordinates_far" + in: + bombs: + - [1, 1, 100000] + - [100000, 100000, 1] + - [99999, 1, 1] + out: 2 + - name: "vertical_chain" + in: + bombs: + - [10, 1, 3] + - [10, 4, 3] + - [10, 7, 3] + - [10, 10, 3] + out: 4 + - name: "horizontal_chain" + in: + bombs: + - [1, 10, 2] + - [3, 10, 2] + - [5, 10, 2] + - [7, 10, 2] + - [9, 10, 2] + out: 5 + - name: "branching_graph" + in: + bombs: + - [5, 5, 5] + - [1, 5, 1] + - [9, 5, 1] + - [5, 1, 1] + - [5, 9, 1] + out: 5 + - name: "small_radius_isolated" + in: + bombs: + - [1, 1, 1] + - [2, 2, 1] + - [3, 3, 1] + - [4, 4, 1] + out: 1 + - name: "nested_ranges" + in: + bombs: + - [50, 50, 1] + - [50, 50, 2] + - [50, 50, 3] + - [50, 50, 4] + - [50, 50, 5] + out: 5 + - name: "diagonal_touch" + in: + bombs: + - [1, 1, 2] + - [2, 2, 1] + - [3, 3, 1] + out: 2 + - name: "diagonal_gap" + in: + bombs: + - [1, 1, 1] + - [2, 2, 1] + - [3, 3, 1] + out: 1 + - name: "asymmetric_radii" + in: + bombs: + - [1, 1, 10] + - [8, 1, 1] + - [15, 1, 1] + - [22, 1, 1] + out: 2 + - name: "overlap_without_chain" + in: + bombs: + - [1, 1, 4] + - [4, 1, 1] + - [8, 1, 4] + out: 2 + - name: "all_at_max_coordinate" + in: + bombs: + - [100000, 100000, 1] + - [100000, 100000, 100000] + - [99999, 100000, 1] + - [100000, 99999, 1] + out: 4 + - name: "five_components" + in: + bombs: + - [1, 1, 1] + - [3, 1, 1] + - [20, 20, 1] + - [22, 20, 1] + - [100, 100, 1] + out: 1 + - name: "dense_small_cluster" + in: + bombs: + - [1, 1, 2] + - [2, 1, 2] + - [1, 2, 2] + - [2, 2, 2] + - [3, 2, 1] + - [2, 3, 1] + out: 6 + - name: "late_bridge" + in: + bombs: + - [1, 1, 2] + - [3, 1, 2] + - [6, 1, 1] + - [8, 1, 2] + - [11, 1, 1] + out: 2 + - name: "boundary_chain_three" + in: + bombs: + - [1, 1, 2] + - [3, 1, 2] + - [5, 1, 2] + out: 3 + - name: "hub_reaches_two_branches" + in: + bombs: + - [10, 10, 5] + - [6, 10, 1] + - [14, 10, 1] + - [6, 12, 1] + - [14, 12, 1] + out: 5 + - name: "radius_one_grid" + in: + bombs: + - [1, 1, 1] + - [2, 1, 1] + - [1, 2, 1] + - [2, 2, 1] + out: 4 + - name: "generated_small_random" + seed: 211 + in: + bombs: + gen: "array" + len: + gen: "int" + min: 1 + max: 12 + of: + gen: "array" + len: 3 + of: + gen: "int" + min: 1 + max: 30 + - name: "generated_medium_random" + seed: 212 + in: + bombs: + gen: "array" + len: + gen: "int" + min: 30 + max: 60 + of: + gen: "array" + len: 3 + of: + gen: "int" + min: 1 + max: 1000 + - name: "generated_dense" + seed: 213 + in: + bombs: + gen: "array" + len: + gen: "int" + min: 80 + max: 100 + of: + gen: "array" + len: 3 + of: + gen: "int" + min: 1 + max: 100000 + - name: "generated_max_coordinates" + seed: 214 + in: + bombs: + gen: "array" + len: 100 + of: + gen: "array" + len: 3 + of: + gen: "int" + min: 99900 + max: 100000 + - name: "generated_max_spread" + seed: 215 + in: + bombs: + gen: "array" + len: 100 + of: + gen: "array" + len: 3 + of: + gen: "int" + min: 1 + max: 100000 diff --git a/tests/2001-2500/2101. detonate-the-maximum-bombs/sol.py b/tests/2001-2500/2101. detonate-the-maximum-bombs/sol.py new file mode 100644 index 00000000..0d13b893 --- /dev/null +++ b/tests/2001-2500/2101. detonate-the-maximum-bombs/sol.py @@ -0,0 +1,30 @@ +class Solution: + def maximumDetonation(self, bombs: List[List[int]]) -> int: + ad_list = defaultdict(list) + + for i in range(len(bombs)): + x1, y1, r1 = bombs[i] + for j in range(len(bombs)): + if i == j: + continue + x2, y2, r2 = bombs[j] + + circle_dist = (x2 -x1)**2 + (y2 - y1)**2 + if circle_dist <= r1**2: + ad_list[i].append(j) + + # Recursive call needs to be added here + def dfs(bomb, visit_set): + visited_set.add(bomb) + for neighbor in ad_list[bomb]: + if neighbor not in visit_set: + dfs(neighbor, visit_set) + + max_bombs = 0 + # Detonating bombs sequentially + for i in range(len(bombs)): + visited_set = set() + dfs(i, visited_set) + max_bombs = max(max_bombs, len(visited_set)) + print(max_bombs) + return max_bombs \ No newline at end of file diff --git a/tests/2001-2500/2102. sequentially-ordinal-rank-tracker/sol.py b/tests/2001-2500/2102. sequentially-ordinal-rank-tracker/sol.py new file mode 100644 index 00000000..a619dd04 --- /dev/null +++ b/tests/2001-2500/2102. sequentially-ordinal-rank-tracker/sol.py @@ -0,0 +1,16 @@ +class Solution: + from sortedcontainers import SortedList + + class SORTracker: + + def __init__(self): + self.cnt = 0 + self.data = SortedList() + + def add(self, location: str, score: int) -> None: + self.data.add((-score, location)) + + def get(self) -> str: + _, location = self.data[self.cnt] + self.cnt+= 1 + return location diff --git a/tests/2001-2500/2103. rings-and-rods/manifest.yaml b/tests/2001-2500/2103. rings-and-rods/manifest.yaml new file mode 100644 index 00000000..a695dd80 --- /dev/null +++ b/tests/2001-2500/2103. rings-and-rods/manifest.yaml @@ -0,0 +1,178 @@ +entry: + id: 2103 + title: "rings-and-rods" + params: + rings: + type: string + call: + cpp: "Solution().countPoints({rings})" + rust: "Solution::count_points({rings})" + python3: "Solution().countPoints({rings})" + python2: "Solution().countPoints({rings})" + ruby: "count_points({rings})" + java: "new Solution().countPoints({rings})" + csharp: "new Solution().CountPoints({rings})" + kotlin: "Solution().countPoints({rings})" + go: "countPoints({rings})" + dart: "Solution().countPoints({rings})" + swift: "Solution().countPoints({rings})" + typescript: "countPoints({rings})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 128 +oracle: + python3: + call: "Checker().countPoints(rings, {result})" + checker: | + class Checker: + def countPoints(self, rings, result): + if not isinstance(result, int): + return False + colors = [set() for _ in range(10)] + for i in range(0, len(rings), 2): + colors[ord(rings[i + 1]) - ord('0')].add(rings[i]) + return result == sum(len(s) == 3 for s in colors) +seed: 2103 +tests: + - name: "example-one" + in: + rings: "B0B6G0R6R0R6G9" + out: 1 + - name: "example-two" + in: + rings: "B0R0G0R9R0B0G0" + out: 1 + - name: "example-three" + in: + rings: "G4" + out: 0 + - name: "single-red" + in: + rings: "R0" + out: 0 + - name: "one-complete-rod" + in: + rings: "R0G0B0" + out: 1 + - name: "different-rods" + in: + rings: "R0G1B2" + out: 0 + - name: "duplicate-colors" + in: + rings: "R0R0G0B0B0" + out: 1 + - name: "two-complete-rods" + in: + rings: "R0G0B0R1G1B1" + out: 2 + - name: "all-ten-complete" + in: + rings: "R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9" + out: 10 + - name: "red-and-green-only" + in: + rings: "R0G0R1G1R2G2" + out: 0 + - name: "blue-last" + in: + rings: "R5G5B5" + out: 1 + - name: "interleaved-complete" + in: + rings: "R3G4B3G3R4B4" + out: 2 + - name: "same-color-many-rods" + in: + rings: "R0R1R2R3R4R5R6R7R8R9" + out: 0 + - name: "three-partial-rods" + in: + rings: "R0G0G1B1B2R2" + out: 0 + - name: "complete-with-noise" + in: + rings: "R2G2B2R3R3B4G5" + out: 1 + - name: "reverse-colors" + in: + rings: "B7G7R7" + out: 1 + - name: "zero-and-nine" + in: + rings: "R0G0B0R9G9B9" + out: 2 + - name: "missing-blue" + in: + rings: "R8G8R8G8" + out: 0 + - name: "missing-red" + in: + rings: "G6B6G6B6" + out: 0 + - name: "missing-green" + in: + rings: "R4B4R4B4" + out: 0 + - name: "five-complete" + in: + rings: "R0G0B0R2G2B2R4G4B4R6G6B6R8G8B8" + out: 5 + - name: "complete-after-duplicates" + in: + rings: "R1R1G1G1B1B1" + out: 1 + - name: "mixed-ten-rods" + in: + rings: "R0G0B0R1G1R2B2G3B3R4R5G5B5G6B6R7G7B8R8G9B9" + out: 2 + - name: "all-rings-one-rod" + in: + rings: "R3G3B3R3G3B3R3G3B3" + out: 1 + - name: "nine-partial-one-complete" + in: + rings: "R0G0B0R1R2R3R4R5R6R7R8R9" + out: 1 + - name: "alternating-pairs" + in: + rings: "R0G1B0R1G0B1" + out: 2 + - name: "complete-at-last-rod" + in: + rings: "R1G2B3R9G9B9" + out: 1 + - name: "all-color-permutations" + in: + rings: "G0B0R0B1R1G1" + out: 2 + - name: "partial-with-duplicates" + in: + rings: "B2B2G2G2R3R3" + out: 0 + - name: "three-complete-separated" + in: + rings: "R0G0B0R5G5B5R9G9B9" + out: 3 + - name: "max-rings-single-color" + in: + rings: "R0R1R2R3R4R5R6R7R8R9R0R1R2R3R4R5R6R7R8R9" + out: 0 + - name: "max-rings-all-complete" + in: + rings: "R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9" + out: 10 + - name: "complete-surrounded-by-partials" + in: + rings: "R1G1R2G2B2R3B3R4G4" + out: 1 + - name: "rod-number-order-irrelevant" + in: + rings: "R9G0B9R0G9B0" + out: 2 + - name: "late-completion" + in: + rings: "R6G6R7G7B7B6" + out: 2 diff --git a/tests/2001-2500/2103. rings-and-rods/sol.py b/tests/2001-2500/2103. rings-and-rods/sol.py new file mode 100644 index 00000000..255a801c --- /dev/null +++ b/tests/2001-2500/2103. rings-and-rods/sol.py @@ -0,0 +1,6 @@ +class Solution: + def countPoints(self, rings: str) -> int: + sets = [set() for _ in range(10)] + for i in range(0, len(rings), 2): + sets[int(rings[i + 1])].add(rings[i]) + return sum(len(s) == 3 for s in sets) \ No newline at end of file diff --git a/tests/2001-2500/2104. sum-of-subarray-ranges/manifest.yaml b/tests/2001-2500/2104. sum-of-subarray-ranges/manifest.yaml new file mode 100644 index 00000000..22316990 --- /dev/null +++ b/tests/2001-2500/2104. sum-of-subarray-ranges/manifest.yaml @@ -0,0 +1,243 @@ +entry: + id: 2104 + title: "sum-of-subarray-ranges" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().subArrayRanges({nums})" + rust: "Solution::sub_array_ranges({nums})" + python3: "Solution().subArrayRanges({nums})" + python2: "Solution().subArrayRanges({nums})" + ruby: "sub_array_ranges({nums})" + java: "new Solution().subArrayRanges({nums})" + csharp: "new Solution().SubArrayRanges({nums})" + kotlin: "Solution().subArrayRanges({nums})" + go: "subArrayRanges({nums})" + dart: "Solution().subArrayRanges({nums})" + swift: "Solution().subArrayRanges({nums})" + typescript: "subArrayRanges({nums})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().subArrayRanges(nums, {result})" + checker: | + class Checker: + def subArrayRanges(self, nums, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + expected = 0 + for i in range(len(nums)): + lo = hi = nums[i] + for j in range(i, len(nums)): + lo = min(lo, nums[j]) + hi = max(hi, nums[j]) + expected += hi - lo + return result == expected + +seed: 2104 + +tests: + - name: "single_positive" + in: + nums: [1] + out: 0 + - name: "all_zero" + in: + nums: [0, 0, 0] + out: 0 + - name: "single_negative" + in: + nums: [-1] + out: 0 + - name: "example_one" + in: + nums: [1, 2, 3] + out: 4 + - name: "example_two_duplicates" + in: + nums: [1, 3, 3] + out: 4 + - name: "example_three" + in: + nums: [4, -2, -3, 4, 1] + out: 59 + - name: "centered_three" + in: + nums: [-1, 0, 1] + out: 4 + - name: "descending_three" + in: + nums: [3, 2, 1] + out: 4 + - name: "all_equal_four" + in: + nums: [1, 1, 1, 1] + out: 0 + - name: "negative_spread" + in: + nums: [-5, -2, -8] + out: 15 + - name: "two_extremes" + in: + nums: [5, -5] + out: 10 + - name: "int_boundary_pair" + in: + nums: [-1000000000, 1000000000] + out: 2000000000 + - name: "alternating_four" + in: + nums: [2, -1, 2, -1] + out: 18 + - name: "mixed_four" + in: + nums: [7, 3, 5, 1] + out: 24 + - name: "plateau_then_rise" + in: + nums: [-3, -3, 0, 2] + out: 18 + - name: "four_mixed_positive" + in: + nums: [1, 4, 2, 5] + out: 18 + - name: "descending_positive" + in: + nums: [9, 8, 7, 6, 5] + out: 20 + - name: "ascending_negative" + in: + nums: [-9, -8, -7, -6] + out: 10 + - name: "repeated_peaks" + in: + nums: [0, 5, 0, 5] + out: 30 + - name: "duplicate_minimum" + in: + nums: [2, 2, 1, 2] + out: 5 + - name: "three_signed" + in: + nums: [-2, 4, -1] + out: 17 + - name: "zero_crossing" + in: + nums: [10, -10, 0] + out: 50 + - name: "five_mixed" + in: + nums: [1, 5, 2, 4, 3] + out: 30 + - name: "negative_duplicates" + in: + nums: [-5, -1, -4, -2] + out: 20 + - name: "repeated_high_low" + in: + nums: [6, 1, 6, 1, 6] + out: 50 + - name: "large_magnitudes_four" + in: + nums: [100, -100, 50, -50] + out: 1000 + - name: "alternating_six" + in: + nums: [1, 2, 1, 2, 1, 2] + out: 15 + - name: "negative_alternating" + in: + nums: [-1, -2, -1, -2] + out: 6 + - name: "ascending_zero" + in: + nums: [0, 1, 2, 3, 4] + out: 20 + - name: "descending_zero" + in: + nums: [4, 3, 2, 1, 0] + out: 20 + - name: "generated_small_signed" + seed: 210401 + in: + nums: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: -1000000000 + max: 1000000000 + distinct: false + sorted: false + elemType: "int" + - name: "generated_duplicates" + seed: 210402 + in: + nums: + gen: "array" + len: + gen: "int" + min: 10 + max: 50 + of: + gen: "int" + min: -3 + max: 3 + distinct: false + sorted: false + elemType: "int" + - name: "generated_medium" + seed: 210403 + in: + nums: + gen: "array" + len: + gen: "int" + min: 100 + max: 250 + of: + gen: "int" + min: -1000000 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + - name: "stress_maximum_signed" + seed: 210404 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: -1000000000 + max: 1000000000 + distinct: false + sorted: false + elemType: "int" + - name: "stress_maximum_nonnegative" + seed: 210405 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: 0 + max: 1000000000 + distinct: false + sorted: false + elemType: "int" diff --git a/tests/2001-2500/2104. sum-of-subarray-ranges/sol.py b/tests/2001-2500/2104. sum-of-subarray-ranges/sol.py new file mode 100644 index 00000000..c3431672 --- /dev/null +++ b/tests/2001-2500/2104. sum-of-subarray-ranges/sol.py @@ -0,0 +1,7 @@ +from itertools import accumulate + + +class Solution: + def subArrayRanges(self, a: List[int]) -> int: + return sum(q for i in range(len(a)) + for q in map(sub,accumulate(a[i:],max),accumulate(a[i:],min))) diff --git a/tests/2001-2500/2105. watering-plants-ii/manifest.yaml b/tests/2001-2500/2105. watering-plants-ii/manifest.yaml new file mode 100644 index 00000000..aabb1b12 --- /dev/null +++ b/tests/2001-2500/2105. watering-plants-ii/manifest.yaml @@ -0,0 +1,326 @@ +entry: + id: 2105 + title: "watering-plants-ii" + params: + plants: + type: array + items: + type: int + capacityA: + type: int + capacityB: + type: int + call: + cpp: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + rust: "Solution::minimum_refill({plants}, {capacityA}, {capacityB})" + python3: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + python2: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + ruby: "minimum_refill({plants}, {capacityA}, {capacityB})" + java: "new Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + csharp: "new Solution().MinimumRefill({plants}, {capacityA}, {capacityB})" + kotlin: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + go: "minimumRefill({plants}, {capacityA}, {capacityB})" + dart: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + swift: "Solution().minimumRefill({plants}, {capacityA}, {capacityB})" + typescript: "minimumRefill({plants}, {capacityA}, {capacityB})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumRefill(plants, capacityA, capacityB, {result})" + checker: | + class Checker: + def minimumRefill(self, plants, capacityA, capacityB, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + left, right = 0, len(plants) - 1 + water_a, water_b = capacityA, capacityB + expected = 0 + while left < right: + if water_a < plants[left]: + expected += 1 + water_a = capacityA + water_a -= plants[left] + if water_b < plants[right]: + expected += 1 + water_b = capacityB + water_b -= plants[right] + left += 1 + right -= 1 + if left == right and max(water_a, water_b) < plants[left]: + expected += 1 + return result == expected + +seed: 21052105 + +tests: + - name: "example_1" + in: + plants: [2, 2, 3, 3] + capacityA: 5 + capacityB: 5 + out: 1 + - name: "example_2" + in: + plants: [2, 2, 3, 3] + capacityA: 3 + capacityB: 4 + out: 2 + - name: "example_3_single_plant" + in: + plants: [5] + capacityA: 10 + capacityB: 8 + out: 0 + - name: "minimum_capacity_single" + in: + plants: [1] + capacityA: 1 + capacityB: 1 + out: 0 + - name: "single_asymmetric_capacity" + in: + plants: [1] + capacityA: 2 + capacityB: 1 + out: 0 + - name: "two_equal_minimum" + in: + plants: [1, 1] + capacityA: 1 + capacityB: 1 + out: 0 + - name: "two_surplus_cans" + in: + plants: [1, 1] + capacityA: 2 + capacityB: 2 + out: 0 + - name: "two_asymmetric_left" + in: + plants: [1, 2] + capacityA: 1 + capacityB: 2 + out: 0 + - name: "two_asymmetric_right" + in: + plants: [2, 1] + capacityA: 2 + capacityB: 1 + out: 0 + - name: "odd_all_minimum" + in: + plants: [1, 1, 1] + capacityA: 1 + capacityB: 1 + out: 1 + - name: "odd_all_surplus" + in: + plants: [1, 1, 1] + capacityA: 2 + capacityB: 2 + out: 0 + - name: "even_exact_capacity" + in: + plants: [5, 5, 5, 5] + capacityA: 5 + capacityB: 5 + out: 2 + - name: "even_one_unit_surplus" + in: + plants: [5, 5, 5, 5] + capacityA: 6 + capacityB: 6 + out: 2 + - name: "odd_middle_refill" + in: + plants: [3, 4, 3, 4, 3] + capacityA: 5 + capacityB: 5 + out: 3 + - name: "odd_middle_asymmetric" + in: + plants: [3, 4, 3, 4, 3] + capacityA: 4 + capacityB: 5 + out: 3 + - name: "alternating_high_low" + in: + plants: [10, 1, 10, 1, 10, 1] + capacityA: 10 + capacityB: 10 + out: 4 + - name: "alternating_low_high" + in: + plants: [1, 10, 1, 10, 1, 10] + capacityA: 10 + capacityB: 10 + out: 4 + - name: "descending_mixed" + in: + plants: [7, 2, 6, 3, 5, 4] + capacityA: 8 + capacityB: 9 + out: 2 + - name: "descending_near_capacity" + in: + plants: [9, 8, 7, 6, 5, 4] + capacityA: 9 + capacityB: 10 + out: 3 + - name: "seven_plants" + in: + plants: [1, 2, 3, 4, 5, 6, 7] + capacityA: 7 + capacityB: 7 + out: 3 + - name: "eight_plants" + in: + plants: [1, 2, 3, 4, 5, 6, 7, 8] + capacityA: 8 + capacityB: 8 + out: 4 + - name: "single_large_value" + in: + plants: [1000000] + capacityA: 1000000000 + capacityB: 1000000000 + out: 0 + - name: "two_large_exact" + in: + plants: [1000000, 1000000] + capacityA: 1000000 + capacityB: 1000000 + out: 0 + - name: "large_middle_odd" + in: + plants: [1, 1000000, 1] + capacityA: 1000000 + capacityB: 1 + out: 1 + - name: "near_int_capacity" + in: + plants: [999999999, 999999999, 999999999, 999999999] + capacityA: 1000000000 + capacityB: 1000000000 + out: 2 + - name: "increasing_nine" + in: + plants: [2, 3, 4, 5, 6, 7, 8, 9, 10] + capacityA: 10 + capacityB: 10 + out: 5 + - name: "decreasing_nine" + in: + plants: [10, 9, 8, 7, 6, 5, 4, 3, 2] + capacityA: 10 + capacityB: 10 + out: 5 + - name: "alternating_capacity_four" + in: + plants: [4, 1, 4, 1, 4, 1, 4, 1] + capacityA: 4 + capacityB: 4 + out: 6 + - name: "alternating_capacity_four_reversed" + in: + plants: [1, 4, 1, 4, 1, 4, 1, 4] + capacityA: 4 + capacityB: 4 + out: 6 + - name: "six_mixed" + in: + plants: [6, 5, 4, 3, 2, 1] + capacityA: 6 + capacityB: 6 + out: 2 + - name: "generated_small_uniform" + seed: 101 + in: + plants: + gen: "array" + len: + gen: "int" + min: 1 + max: 40 + of: + gen: "int" + min: 1 + max: 20 + distinct: false + sorted: false + elemType: "int" + capacityA: 20 + capacityB: 20 + - name: "generated_small_high_capacity" + seed: 102 + in: + plants: + gen: "array" + len: + gen: "int" + min: 1 + max: 80 + of: + gen: "int" + min: 1 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + capacityA: 1000000000 + capacityB: 1000000000 + - name: "generated_boundary_values" + seed: 103 + in: + plants: + gen: "array" + len: + gen: "int" + min: 90 + max: 120 + of: + gen: "int" + min: 999000 + max: 999500 + distinct: false + sorted: false + elemType: "int" + capacityA: 1000000 + capacityB: 999500 + - name: "generated_large" + seed: 104 + in: + plants: + gen: "array" + len: 90000 + of: + gen: "int" + min: 1 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + capacityA: 1000000000 + capacityB: 1000000000 + - name: "generated_maximum" + seed: 105 + in: + plants: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + capacityA: 1000000 + capacityB: 1000000 diff --git a/tests/2001-2500/2105. watering-plants-ii/sol.py b/tests/2001-2500/2105. watering-plants-ii/sol.py new file mode 100644 index 00000000..2b1d7881 --- /dev/null +++ b/tests/2001-2500/2105. watering-plants-ii/sol.py @@ -0,0 +1,32 @@ +class Solution(object): + def minimumRefill(self, plants, capacityA, capacityB): + """ + :type plants: List[int] + :type capacityA: int + :type capacityB: int + :rtype: int + """ + n = len(plants) + left, right = 0, n - 1 + waterA, waterB = capacityA, capacityB + refills = 0 + + while left < right: + if waterA < plants[left]: + refills += 1 + waterA = capacityA + waterA -= plants[left] + + if waterB < plants[right]: + refills += 1 + waterB = capacityB + waterB -= plants[right] + + left += 1 + right -= 1 + + if left == right: + if max(waterA, waterB) < plants[left]: + refills += 1 + + return refills \ No newline at end of file diff --git a/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/manifest.yaml b/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/manifest.yaml new file mode 100644 index 00000000..27be1166 --- /dev/null +++ b/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/manifest.yaml @@ -0,0 +1,509 @@ +entry: + id: 2106 + title: "maximum-fruits-harvested-after-at-most-k-steps" + params: + fruits: + type: array + items: + type: array + items: + type: int + startPos: + type: int + k: + type: int + call: + cpp: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + rust: "Solution::max_total_fruits({fruits}, {startPos}, {k})" + python3: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + python2: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + ruby: "max_total_fruits({fruits}, {startPos}, {k})" + java: "new Solution().maxTotalFruits({fruits}, {startPos}, {k})" + csharp: "new Solution().MaxTotalFruits({fruits}, {startPos}, {k})" + kotlin: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + go: "maxTotalFruits({fruits}, {startPos}, {k})" + dart: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + swift: "Solution().maxTotalFruits({fruits}, {startPos}, {k})" + typescript: "maxTotalFruits({fruits}, {startPos}, {k})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maxTotalFruits(fruits, startPos, k, {result})" + checker: | + class Checker: + def maxTotalFruits(self, fruits, startPos, k, result): + if not isinstance(result, int): + return False + best = 0 + for i, (left, _) in enumerate(fruits): + for j in range(i, len(fruits)): + right = fruits[j][0] + cost = min(abs(startPos - left) + right - left, + abs(startPos - right) + right - left) + if cost <= k: + best = max(best, sum(amount for _, amount in fruits[i:j + 1])) + return result == best + +seed: 2106 + +tests: + - name: "example_1" + in: + fruits: + elemType: "int" + value: + - [2, 8] + - [6, 3] + - [8, 6] + startPos: 5 + k: 4 + out: 9 + - name: "example_2" + in: + fruits: + elemType: "int" + value: + - [0, 9] + - [4, 1] + - [5, 7] + - [6, 2] + - [7, 4] + - [10, 9] + startPos: 5 + k: 4 + out: 14 + - name: "example_3" + in: + fruits: + elemType: "int" + value: + - [0, 3] + - [6, 4] + - [8, 5] + startPos: 3 + k: 2 + out: 0 + - name: "single_at_start" + in: + fruits: + elemType: "int" + value: + - [10, 7] + startPos: 10 + k: 0 + out: 7 + - name: "single_left_reachable" + in: + fruits: + elemType: "int" + value: + - [3, 11] + startPos: 5 + k: 2 + out: 11 + - name: "single_right_unreachable" + in: + fruits: + elemType: "int" + value: + - [8, 11] + startPos: 5 + k: 2 + out: 0 + - name: "zero_steps_with_start_fruit" + in: + fruits: + elemType: "int" + value: + - [4, 3] + - [5, 13] + - [6, 2] + startPos: 5 + k: 0 + out: 13 + - name: "all_left" + in: + fruits: + elemType: "int" + value: + - [1, 2] + - [3, 4] + - [5, 8] + startPos: 6 + k: 5 + out: 14 + - name: "all_right" + in: + fruits: + elemType: "int" + value: + - [6, 5] + - [8, 7] + - [10, 9] + startPos: 6 + k: 4 + out: 21 + - name: "turn_left_then_right" + in: + fruits: + elemType: "int" + value: + - [2, 5] + - [4, 6] + - [7, 20] + - [9, 1] + startPos: 5 + k: 5 + out: 26 + - name: "turn_right_then_left" + in: + fruits: + elemType: "int" + value: + - [1, 10] + - [3, 2] + - [6, 30] + - [8, 4] + startPos: 5 + k: 6 + out: 42 + - name: "boundary_exact_left" + in: + fruits: + elemType: "int" + value: + - [0, 17] + - [2, 3] + - [5, 2] + startPos: 5 + k: 5 + out: 22 + - name: "boundary_exact_right" + in: + fruits: + elemType: "int" + value: + - [5, 2] + - [8, 3] + - [10, 19] + startPos: 5 + k: 5 + out: 24 + - name: "gap_blocks_middle" + in: + fruits: + elemType: "int" + value: + - [0, 5] + - [10, 50] + - [11, 4] + - [20, 60] + startPos: 10 + k: 3 + out: 54 + - name: "start_between_sparse" + in: + fruits: + elemType: "int" + value: + - [0, 8] + - [4, 6] + - [9, 7] + - [15, 10] + startPos: 6 + k: 5 + out: 7 + - name: "duplicate_amounts" + in: + fruits: + elemType: "int" + value: + - [2, 5] + - [3, 5] + - [4, 5] + - [5, 5] + - [6, 5] + startPos: 4 + k: 2 + out: 15 + - name: "large_amount_single" + in: + fruits: + elemType: "int" + value: + - [100000, 10000] + startPos: 0 + k: 200000 + out: 10000 + - name: "positions_at_zero" + in: + fruits: + elemType: "int" + value: + - [0, 1] + - [1, 2] + - [2, 3] + startPos: 0 + k: 2 + out: 6 + - name: "positions_at_max" + in: + fruits: + elemType: "int" + value: + - [199998, 4] + - [199999, 5] + - [200000, 6] + startPos: 200000 + k: 2 + out: 15 + - name: "high_value_far_left" + in: + fruits: + elemType: "int" + value: + - [0, 10000] + - [100, 1] + - [200, 1] + startPos: 100 + k: 100 + out: 10001 + - name: "high_value_far_right" + in: + fruits: + elemType: "int" + value: + - [0, 1] + - [100, 1] + - [200, 10000] + startPos: 100 + k: 100 + out: 10001 + - name: "prefer_one_side_over_turn" + in: + fruits: + elemType: "int" + value: + - [1, 100] + - [4, 1] + - [6, 1] + - [9, 1] + startPos: 5 + k: 4 + out: 101 + - name: "dense_window_left" + in: + fruits: + elemType: "int" + value: + - [0, 1] + - [1, 2] + - [2, 3] + - [3, 4] + - [4, 5] + - [5, 6] + - [6, 7] + - [7, 8] + startPos: 6 + k: 5 + out: 30 + - name: "dense_window_right" + in: + fruits: + elemType: "int" + value: + - [10, 8] + - [11, 7] + - [12, 6] + - [13, 5] + - [14, 4] + - [15, 3] + - [16, 2] + - [17, 1] + startPos: 11 + k: 4 + out: 26 + - name: "mixed_window" + in: + fruits: + elemType: "int" + value: + - [2, 9] + - [4, 1] + - [5, 8] + - [7, 2] + - [8, 10] + - [11, 3] + startPos: 6 + k: 5 + out: 20 + - name: "start_before_everything" + in: + fruits: + elemType: "int" + value: + - [5, 2] + - [7, 4] + - [9, 8] + - [12, 16] + startPos: 0 + k: 10 + out: 14 + - name: "start_after_everything" + in: + fruits: + elemType: "int" + value: + - [0, 2] + - [3, 4] + - [5, 8] + - [8, 16] + startPos: 10 + k: 10 + out: 30 + - name: "far_fruit_unreachable" + in: + fruits: + elemType: "int" + value: + - [0, 10000] + - [200000, 9999] + startPos: 100000 + k: 99999 + out: 0 + - name: "two_sided_overlap" + in: + fruits: + elemType: "int" + value: + - [3, 4] + - [5, 6] + - [7, 8] + - [9, 10] + startPos: 6 + k: 4 + out: 18 + - name: "turnaround_cost_matters" + in: + fruits: + elemType: "int" + value: + - [0, 20] + - [2, 1] + - [5, 30] + - [6, 40] + startPos: 4 + k: 6 + out: 71 + - name: "maximum_count_small_amounts" + in: + fruits: + elemType: "int" + value: + - [0, 1] + - [2, 1] + - [4, 1] + - [6, 1] + - [8, 1] + - [10, 1] + startPos: 5 + k: 7 + out: 4 + - name: "large_gap_exact_reach" + in: + fruits: + elemType: "int" + value: + - [1, 2] + - [50000, 300] + - [100000, 400] + - [150000, 500] + startPos: 100000 + k: 50000 + out: 900 + - name: "near_constraint_amount_sum" + in: + fruits: + elemType: "int" + value: + - [99990, 10000] + - [99995, 10000] + - [100000, 10000] + - [100005, 10000] + - [100010, 10000] + startPos: 100000 + k: 10 + out: 30000 + - name: "long_sparse_chain" + in: + fruits: + elemType: "int" + value: + - [0, 10] + - [25000, 20] + - [50000, 30] + - [75000, 40] + - [100000, 50] + - [125000, 60] + - [150000, 70] + - [175000, 80] + - [200000, 90] + startPos: 100000 + k: 100000 + out: 350 + - name: "max_positions_dense_end" + in: + fruits: + elemType: "int" + value: + - [199990, 1] + - [199991, 2] + - [199992, 3] + - [199993, 4] + - [199994, 5] + - [199995, 6] + - [199996, 7] + - [199997, 8] + - [199998, 9] + - [199999, 10] + - [200000, 11] + startPos: 199995 + k: 10 + out: 60 + - name: "max_k_reaches_both_ends" + in: + fruits: + elemType: "int" + value: + - [0, 2] + - [1, 3] + - [199999, 4] + - [200000, 5] + startPos: 100000 + k: 200000 + out: 9 + - name: "one_hundred_positions_pattern" + in: + fruits: + elemType: "int" + value: + - [100, 1] + - [101, 2] + - [102, 3] + - [103, 4] + - [104, 5] + - [105, 6] + - [106, 7] + - [107, 8] + - [108, 9] + - [109, 10] + startPos: 105 + k: 6 + out: 45 diff --git a/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/sol.py b/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/sol.py new file mode 100644 index 00000000..433ffd68 --- /dev/null +++ b/tests/2001-2500/2106. maximum-fruits-harvested-after-at-most-k-steps/sol.py @@ -0,0 +1,13 @@ +class Solution: + def maxTotalFruits(self, fruits, startPos: int, k: int) -> int: + left = total = res = 0 + for right in range(len(fruits)): + total += fruits[right][1] + while left <= right and min( + abs(startPos - fruits[left][0]) + fruits[right][0] - fruits[left][0], + abs(startPos - fruits[right][0]) + fruits[right][0] - fruits[left][0] + ) > k: + total -= fruits[left][1] + left += 1 + res = max(res, total) + return res \ No newline at end of file diff --git a/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/manifest.yaml b/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/manifest.yaml new file mode 100644 index 00000000..5ad02e38 --- /dev/null +++ b/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/manifest.yaml @@ -0,0 +1,249 @@ +entry: + id: 2108 + title: "find-first-palindromic-string-in-the-array" + params: + words: + type: array + items: + type: string + call: + cpp: "Solution().firstPalindrome({words})" + rust: "Solution::first_palindrome({words})" + python3: "Solution().firstPalindrome({words})" + python2: "Solution().firstPalindrome({words})" + ruby: "first_palindrome({words})" + java: "new Solution().firstPalindrome({words})" + csharp: "new Solution().FirstPalindrome({words})" + kotlin: "Solution().firstPalindrome({words})" + go: "firstPalindrome({words})" + dart: "Solution().firstPalindrome({words})" + swift: "Solution().firstPalindrome({words})" + typescript: "firstPalindrome({words})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().firstPalindrome(words, {result})" + checker: | + class Checker: + def firstPalindrome(self, words, result): + expected = "" + for word in words: + if word == word[::-1]: + expected = word + break + return isinstance(result, str) and result == expected + +seed: 2108 + +tests: + - name: "example_first_middle" + in: + words: ["abc", "car", "ada", "racecar", "cool"] + out: "ada" + - name: "example_only_palindrome" + in: + words: ["notapalindrome", "racecar"] + out: "racecar" + - name: "example_none" + in: + words: ["def", "ghi"] + out: "" + - name: "single_character" + in: + words: ["a"] + out: "a" + - name: "single_nonpalindrome" + in: + words: ["ab"] + out: "" + - name: "single_even_palindrome" + in: + words: ["aa"] + out: "aa" + - name: "single_odd_palindrome" + in: + words: ["aba"] + out: "aba" + - name: "first_word_palindrome" + in: + words: ["level", "world", "noon"] + out: "level" + - name: "last_word_palindrome" + in: + words: ["abc", "def", "ghi", "racecar"] + out: "racecar" + - name: "palindrome_after_many_failures" + in: + words: ["ab", "bc", "cd", "de", "ef", "fg", "gg"] + out: "gg" + - name: "later_palindrome_not_selected" + in: + words: ["rotor", "level", "civic"] + out: "rotor" + - name: "duplicate_palindromes" + in: + words: ["abc", "aba", "aba", "abba"] + out: "aba" + - name: "duplicate_nonpalindromes" + in: + words: ["abc", "abc", "abca"] + out: "" + - name: "empty_string_not_allowed_but_result" + in: + words: ["ab", "ba", "cab"] + out: "" + - name: "length_one_words" + in: + words: ["x", "y", "z"] + out: "x" + - name: "mixed_short_words" + in: + words: ["ab", "a", "bc", "cc"] + out: "a" + - name: "even_length_first" + in: + words: ["abba", "abcba", "abcd"] + out: "abba" + - name: "odd_length_first" + in: + words: ["abcba", "abba", "abca"] + out: "abcba" + - name: "near_palindrome_failure" + in: + words: ["abca", "abcda", "abcdef", "a"] + out: "a" + - name: "different_center" + in: + words: ["abccba", "abccbb", "abcxcba"] + out: "abccba" + - name: "all_same_letter" + in: + words: ["zzzz", "z", "zz"] + out: "zzzz" + - name: "all_distinct_letters" + in: + words: ["a", "b", "c"] + out: "a" + - name: "long_odd_palindrome" + in: + words: ["abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba"] + out: "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba" + - name: "long_even_palindrome" + in: + words: ["abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba"] + out: "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba" + - name: "long_failure_then_palindrome" + in: + words: ["abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcbz", "mnoponm"] + out: "mnoponm" + - name: "palindrome_prefix_failure" + in: + words: ["aaaaab", "baaaaa", "aaaacaaa", "bbbb"] + out: "bbbb" + - name: "palindrome_suffix_failure" + in: + words: ["baaaaa", "aaaaab", "ccccd", "ddddd"] + out: "ddddd" + - name: "case_sensitive_not_relevant_lowercase" + in: + words: ["mnop", "noon", "ponop"] + out: "noon" + - name: "ten_word_mix" + in: + words: ["ab", "bc", "cd", "de", "ef", "fg", "gh", "hi", "ij", "jj"] + out: "jj" + - name: "first_of_two_candidates" + in: + words: ["abcdcba", "abcddcba", "abcd"] + out: "abcdcba" + - name: "palindrome_length_100" + in: + words: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + out: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - name: "nonpalindrome_length_100" + in: + words: ["baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + out: "" + - name: "maximum_array_all_fail" + in: + words: ["ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az"] + out: "" + - name: "first_after_repeated_failures" + in: + words: ["ba", "cb", "dc", "ed", "fe", "gf", "hg", "ih", "ji", "kj", "lk", "ml", "nm", "on", "po", "qp", "rq", "sr", "ts", "ut", "vu", "wv", "xw", "yx", "zy", "xyzzyx"] + out: "xyzzyx" + - name: "generated_small_mixed" + seed: 11 + in: + words: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 12 + alphabet: "abc" + - name: "generated_medium_binary" + seed: 22 + in: + words: + gen: "array" + len: + gen: "int" + min: 20 + max: 60 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 40 + alphabet: "ab" + - name: "generated_short_many" + seed: 33 + in: + words: + gen: "array" + len: + gen: "int" + min: 80 + max: 100 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 5 + alphabet: "abcd" + - name: "stress_max_array" + seed: 44 + in: + words: + gen: "array" + len: 100 + of: + gen: "str" + len: 100 + alphabet: "abcdef" + - name: "stress_max_binary_strings" + seed: 55 + in: + words: + gen: "array" + len: 100 + of: + gen: "str" + len: 100 + alphabet: "ab" diff --git a/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/sol.py b/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/sol.py new file mode 100644 index 00000000..6eb29105 --- /dev/null +++ b/tests/2001-2500/2108. find-first-palindromic-string-in-the-array/sol.py @@ -0,0 +1,19 @@ +class Solution: + def firstPalindrome(self, words): + """ + :type words: list of str + :rtype: str + """ + for word in words: + if self.isPalindrome(word): + return word + return "" + + def isPalindrome(self, s): + i, j = 0, len(s) - 1 + while i < j: + if s[i] != s[j]: + return False + i += 1 + j -= 1 + return True \ No newline at end of file diff --git a/tests/2001-2500/2109. adding-spaces-to-a-string/manifest.yaml b/tests/2001-2500/2109. adding-spaces-to-a-string/manifest.yaml new file mode 100644 index 00000000..3f44dc1d --- /dev/null +++ b/tests/2001-2500/2109. adding-spaces-to-a-string/manifest.yaml @@ -0,0 +1,249 @@ +entry: + id: 2109 + title: "adding-spaces-to-a-string" + params: + s: + type: string + spaces: + type: array + items: + type: int + call: + cpp: "Solution().addSpaces({s}, {spaces})" + rust: "Solution::add_spaces({s}, {spaces})" + python3: "Solution().addSpaces({s}, {spaces})" + python2: "Solution().addSpaces({s}, {spaces})" + ruby: "add_spaces({s}, {spaces})" + java: "new Solution().addSpaces({s}, {spaces})" + csharp: "new Solution().AddSpaces({s}, {spaces})" + kotlin: "Solution().addSpaces({s}, {spaces})" + go: "addSpaces({s}, {spaces})" + dart: "Solution().addSpaces({s}, {spaces})" + swift: "Solution().addSpaces({s}, {spaces})" + typescript: "addSpaces({s}, {spaces})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 300 +oracle: + python3: + call: "Checker().addSpaces(s, spaces, {result})" + checker: | + class Checker: + def addSpaces(self, s, spaces, result): + parts = [] + previous = 0 + for index in spaces: + parts.append(s[previous:index]) + parts.append(" ") + previous = index + parts.append(s[previous:]) + return result == "".join(parts) +seed: 2109 +tests: + - name: "example_1" + in: + s: "LeetcodeHelpsMeLearn" + spaces: [8, 13, 15] + out: "Leetcode Helps Me Learn" + - name: "example_2" + in: + s: "icodeinpython" + spaces: [1, 5, 7, 9] + out: "i code in py thon" + - name: "example_3" + in: + s: "spacing" + spaces: [0, 1, 2, 3, 4, 5, 6] + out: " s p a c i n g" + - name: "single_lower" + in: + s: "a" + spaces: [0] + out: " a" + - name: "single_upper" + in: + s: "Z" + spaces: [0] + out: " Z" + - name: "first_only" + in: + s: "hello" + spaces: [0] + out: " hello" + - name: "last_only" + in: + s: "hello" + spaces: [4] + out: "hell o" + - name: "first_and_last" + in: + s: "abcde" + spaces: [0, 4] + out: " abcd e" + - name: "middle_only" + in: + s: "abcdef" + spaces: [3] + out: "abc def" + - name: "consecutive_indices" + in: + s: "abcdefgh" + spaces: [2, 3, 4] + out: "ab c d efgh" + - name: "alternating_positions" + in: + s: "abcdefghij" + spaces: [1, 3, 5, 7, 9] + out: "a bc de fg hi j" + - name: "case_mix" + in: + s: "AaBbCcDd" + spaces: [1, 2, 5] + out: "A a BbC cDd" + - name: "all_but_last" + in: + s: "abcdef" + spaces: [0, 1, 2, 3, 4] + out: " a b c d ef" + - name: "two_letters" + in: + s: "xy" + spaces: [1] + out: "x y" + - name: "long_gap" + in: + s: "abcdefghijklmnopqrst" + spaces: [10] + out: "abcdefghij klmnopqrst" + - name: "many_chunks" + in: + s: "abcdefghijklmnop" + spaces: [1, 4, 8, 12] + out: "a bcd efgh ijkl mnop" + - name: "mixed_edges" + in: + s: "aBcDeFgHiJ" + spaces: [0, 3, 6, 9] + out: " aBc DeF gHi J" + - name: "repeated_pattern" + in: + s: "AaAaAaAa" + spaces: [2, 4, 6] + out: "Aa Aa Aa Aa" + - name: "dense_prefix" + in: + s: "abcdefghij" + spaces: [0, 1, 2, 3] + out: " a b c defghij" + - name: "dense_suffix" + in: + s: "abcdefghij" + spaces: [6, 7, 8, 9] + out: "abcdef g h i j" + - name: "boundary_pair" + in: + s: "abcdefghijkl" + spaces: [1, 10] + out: "a bcdefghij kl" + - name: "balanced_chunks" + in: + s: "abcdefghijklmnopqr" + spaces: [3, 6, 9, 12, 15] + out: "abc def ghi jkl mno pqr" + - name: "alternating_case" + in: + s: "aAbBcCdDeEfFgG" + spaces: [2, 5, 8, 11] + out: "aA bBc CdD eEf FgG" + - name: "all_upper_positions" + in: + s: "ABCDE" + spaces: [0, 1, 2, 3, 4] + out: " A B C D E" + - name: "near_end" + in: + s: "Qwerty" + spaces: [5] + out: "Qwert y" + - name: "wide_chunks" + in: + s: "abcdefghijklmnopqrstuvwx" + spaces: [5, 12, 19] + out: "abcde fghijkl mnopqrs tuvwx" + - name: "ten_insertions" + in: + s: "abcdefghijklmnopqrst" + spaces: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] + out: " ab cd ef gh ij kl mn op qr st" + - name: "irregular_one" + in: + s: "xYzAbCdeFGhijK" + spaces: [1, 4, 7, 10, 13] + out: "x YzA bCd eFG hij K" + - name: "irregular_two" + in: + s: "mnoPQRstuVwxyz" + spaces: [3, 5, 9, 12] + out: "mno PQ Rstu Vwx yz" + - name: "generated_short" + seed: 1 + in: + s: + gen: "str" + len: 37 + alphabet: "aBcD" + spaces: [0, 1, 7, 18, 36] + - name: "generated_medium" + seed: 2 + in: + s: + gen: "str" + len: 251 + alphabet: "azAZ" + spaces: [0, 3, 17, 64, 128, 250] + - name: "generated_dense" + seed: 3 + in: + s: + gen: "str" + len: 1000 + alphabet: "ab" + spaces: [0, 1, 2, 3, 4, 5, 10, 100, 500, 999] + - name: "generated_large" + seed: 4 + in: + s: + gen: "str" + len: 299999 + alphabet: "aBc" + spaces: [0, 1, 100, 10000, 100000, 200000, 299998] + - name: "generated_maximum" + seed: 5 + in: + s: + gen: "str" + len: 300000 + alphabet: "Az" + spaces: [0, 299999] + - name: "final_boundary_pair" + in: + s: "abcdefghijklmnopqrstu" + spaces: [1, 20] + out: "a bcdefghijklmnopqrst u" + - name: "three_characters" + in: + s: "AbC" + spaces: [0, 2] + out: " Ab C" + - name: "long_prefix" + in: + s: "abcdefghijklmnopqrstuv" + spaces: [1, 2, 3, 4, 5] + out: "a b c d e fghijklmnopqrstuv" + - name: "single_middle_upper" + in: + s: "ABCDEFGHIJKLMNOP" + spaces: [8] + out: "ABCDEFGH IJKLMNOP" diff --git a/tests/2001-2500/2109. adding-spaces-to-a-string/sol.py b/tests/2001-2500/2109. adding-spaces-to-a-string/sol.py new file mode 100644 index 00000000..a78c40a0 --- /dev/null +++ b/tests/2001-2500/2109. adding-spaces-to-a-string/sol.py @@ -0,0 +1,10 @@ +class Solution: + def addSpaces(self, s, spaces): + result = [] + previous = 0 + for index in spaces: + result.append(s[previous:index]) + result.append(" ") + previous = index + result.append(s[previous:]) + return "".join(result) diff --git a/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/manifest.yaml b/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/manifest.yaml new file mode 100644 index 00000000..67fd1329 --- /dev/null +++ b/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/manifest.yaml @@ -0,0 +1,237 @@ +entry: + id: 2110 + title: "number-of-smooth-descent-periods-of-a-stock" + params: + prices: + type: array + items: + type: int + call: + cpp: "Solution().getDescentPeriods({prices})" + rust: "Solution::get_descent_periods({prices})" + python3: "Solution().getDescentPeriods({prices})" + python2: "Solution().getDescentPeriods({prices})" + ruby: "get_descent_periods({prices})" + java: "new Solution().getDescentPeriods({prices})" + csharp: "new Solution().GetDescentPeriods({prices})" + kotlin: "Solution().getDescentPeriods({prices})" + go: "getDescentPeriods({prices})" + dart: "Solution().getDescentPeriods({prices})" + swift: "Solution().getDescentPeriods({prices})" + typescript: "getDescentPeriods({prices})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 256 + +oracle: + python3: + call: "Checker().getDescentPeriods(prices, {result})" + checker: | + class Checker: + def getDescentPeriods(self, prices, result): + expected = 0 + run = 0 + for i, value in enumerate(prices): + if i > 0 and prices[i - 1] - value == 1: + run += 1 + else: + run = 1 + expected += run + return result == expected + +seed: 2110 + +tests: + - name: "example_three_singleton" + in: + prices: [1] + out: 1 + - name: "example_one" + in: + prices: [3, 2, 1, 4] + out: 7 + - name: "example_two" + in: + prices: [8, 6, 7, 7] + out: 4 + - name: "two_day_descent" + in: + prices: [2, 1] + out: 3 + - name: "two_day_non_descent" + in: + prices: [1, 2] + out: 2 + - name: "minimum_values" + in: + prices: [1, 1, 1, 1] + out: 4 + - name: "maximum_values" + in: + prices: [100000, 100000, 100000] + out: 3 + - name: "full_run_length_five" + in: + prices: [5, 4, 3, 2, 1] + out: 15 + - name: "full_run_length_six" + in: + prices: [6, 5, 4, 3, 2, 1] + out: 21 + - name: "run_then_jump" + in: + prices: [10, 9, 8, 3, 2, 1] + out: 12 + - name: "jump_then_run" + in: + prices: [10, 1, 1] + out: 3 + - name: "increase_breaks_run" + in: + prices: [5, 4, 5, 4, 3] + out: 9 + - name: "larger_drop_breaks" + in: + prices: [10, 8, 7, 5, 4] + out: 7 + - name: "repeat_breaks" + in: + prices: [5, 4, 4, 3, 2] + out: 9 + - name: "alternating_extremes" + in: + prices: [1, 100000, 1, 100000, 1] + out: 5 + - name: "alternating_unit_and_break" + in: + prices: [9, 8, 10, 9, 7, 6, 8] + out: 10 + - name: "long_middle_run" + in: + prices: [20, 19, 18, 17, 16, 10, 9, 8, 3] + out: 22 + - name: "boundary_descent" + in: + prices: [5, 4, 3, 2, 1] + out: 15 + - name: "boundary_start_minimum" + in: + prices: [1, 2, 3, 4, 5] + out: 5 + - name: "mixed_short_one" + in: + prices: [7, 6, 5, 9, 8, 7, 6, 10] + out: 17 + - name: "mixed_short_two" + in: + prices: [4, 3, 2, 8, 7, 7, 6, 5, 1] + out: 16 + - name: "mixed_short_three" + in: + prices: [100, 99, 98, 97, 50, 49, 48, 47, 46, 45] + out: 31 + - name: "isolated_valid_pairs" + in: + prices: [10, 9, 20, 19, 30, 29] + out: 9 + - name: "descending_with_zero_impossible" + in: + prices: [3, 2, 1, 1, 2, 1] + out: 10 + - name: "near_max_contiguous" + in: + prices: [100000, 99999, 99998, 99997, 99996, 99995, 99994] + out: 28 + - name: "near_min_contiguous" + in: + prices: [7, 6, 5, 4, 3, 2, 1] + out: 28 + - name: "single_break_in_run" + in: + prices: [12, 11, 10, 9, 20, 8, 7, 6] + out: 17 + - name: "all_distinct_non_unit" + in: + prices: [1, 3, 5, 7, 9, 11] + out: 6 + - name: "unit_drop_after_increase" + in: + prices: [2, 4, 3, 2, 5, 4] + out: 10 + - name: "several_runs" + in: + prices: [9, 8, 7, 20, 19, 15, 14, 13, 12, 30] + out: 20 + - name: "short_max_drop" + in: + prices: [100000, 99999] + out: 3 + - name: "generated_small_random" + in: + prices: + gen: "array" + len: 37 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + seed: 211001 + - name: "generated_medium_random" + in: + prices: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + seed: 211002 + - name: "generated_large_random" + in: + prices: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + seed: 211003 + - name: "generated_large_constant" + in: + prices: + gen: "array" + len: 100000 + of: + gen: "int" + min: 50000 + max: 50000 + distinct: false + sorted: false + elemType: "int" + seed: 211004 + - name: "generated_boundary_random" + in: + prices: + gen: "array" + len: 5000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + seed: 211005 diff --git a/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/sol.py b/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/sol.py new file mode 100644 index 00000000..f0dcdbc1 --- /dev/null +++ b/tests/2001-2500/2110. number-of-smooth-descent-periods-of-a-stock/sol.py @@ -0,0 +1,8 @@ +class Solution: + def getDescentPeriods(self, prices: List[int]) -> int: + sum, des, prev=0, 0, -1 + for x in prices: + des=(-((x+1)==prev) & des)+1 + sum+=des + prev=x + return sum \ No newline at end of file diff --git a/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/manifest.yaml b/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/manifest.yaml new file mode 100644 index 00000000..574e34a8 --- /dev/null +++ b/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/manifest.yaml @@ -0,0 +1,259 @@ +entry: + id: 2111 + title: "minimum-operations-to-make-the-array-k-increasing" + params: + arr: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().kIncreasing({arr}, {k})" + rust: "Solution::k_increasing({arr}, {k})" + python3: "Solution().kIncreasing({arr}, {k})" + python2: "Solution().kIncreasing({arr}, {k})" + ruby: "k_increasing({arr}, {k})" + java: "new Solution().kIncreasing({arr}, {k})" + csharp: "new Solution().KIncreasing({arr}, {k})" + kotlin: "Solution().kIncreasing({arr}, {k})" + go: "kIncreasing({arr}, {k})" + dart: "Solution().kIncreasing({arr}, {k})" + swift: "Solution().kIncreasing({arr}, {k})" + typescript: "kIncreasing({arr}, {k})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 300 +oracle: + python3: + call: "Checker().kIncreasing(arr, k, {result})" + checker: | + from bisect import bisect_right + class Checker: + def kIncreasing(self, arr, k, result): + if not isinstance(result, int): + return False + keep = 0 + for start in range(k): + lis = [] + for value in arr[start::k]: + pos = bisect_right(lis, value) + if pos == len(lis): + lis.append(value) + else: + lis[pos] = value + keep += len(lis) + return result == len(arr) - keep +seed: 2111 +tests: + - name: "example_1" + in: + arr: [5, 4, 3, 2, 1] + k: 1 + out: 4 + - name: "example_2" + in: + arr: [4, 1, 5, 2, 6, 2] + k: 2 + out: 0 + - name: "example_3" + in: + arr: [4, 1, 5, 2, 6, 2] + k: 3 + out: 2 + - name: "single_element" + in: + arr: [1] + k: 1 + out: 0 + - name: "all_equal" + in: + arr: [7, 7, 7, 7] + k: 1 + out: 0 + - name: "increasing_k_one" + in: + arr: [1, 2, 3, 4, 5] + k: 1 + out: 0 + - name: "descending_k_one" + in: + arr: [9, 8, 7, 6, 5, 4, 3, 2, 1] + k: 1 + out: 8 + - name: "descending_k_two" + in: + arr: [5, 4, 3, 2, 1] + k: 2 + out: 3 + - name: "alternating_two_chains" + in: + arr: [1, 100, 2, 99, 3, 98] + k: 2 + out: 2 + - name: "three_chain_reversals" + in: + arr: [10, 1, 10, 1, 10, 1] + k: 3 + out: 2 + - name: "duplicate_chain_values" + in: + arr: [3, 1, 2, 1, 2, 1, 3] + k: 2 + out: 1 + - name: "descending_three_chains" + in: + arr: [9, 8, 7, 6, 5, 4, 3, 2, 1] + k: 3 + out: 6 + - name: "interleaved_nonmonotonic" + in: + arr: [1, 2, 1, 2, 1, 2, 1, 2] + k: 3 + out: 2 + - name: "large_values" + in: + arr: [1000000000, 1, 999999999, 2] + k: 1 + out: 2 + - name: "mostly_valid_pairs" + in: + arr: [2, 1, 3, 1, 4, 1] + k: 2 + out: 0 + - name: "pair_chain_drops" + in: + arr: [1, 3, 2, 4, 3, 5] + k: 2 + out: 0 + - name: "k_equals_n_descending" + in: + arr: [6, 5, 4, 3, 2, 1] + k: 6 + out: 0 + - name: "k_equals_n_increasing" + in: + arr: [1, 2, 3, 4, 5, 6] + k: 6 + out: 0 + - name: "duplicate_blocks" + in: + arr: [2, 2, 1, 1, 3, 3] + k: 1 + out: 2 + - name: "four_residue_chains" + in: + arr: [8, 1, 7, 2, 6, 3, 5, 4] + k: 4 + out: 2 + - name: "two_residue_mixed" + in: + arr: [1, 9, 2, 8, 3, 7, 4, 6, 5] + k: 2 + out: 3 + - name: "constant_one" + in: + arr: [1] + k: 1 + out: 0 + - name: "two_elements_drop" + in: + arr: [2, 1] + k: 1 + out: 1 + - name: "two_elements_equal" + in: + arr: [2, 2] + k: 1 + out: 0 + - name: "three_elements_middle_drop" + in: + arr: [1, 3, 2] + k: 1 + out: 1 + - name: "k_two_singletons" + in: + arr: [3, 1, 2] + k: 2 + out: 1 + - name: "k_three_short_chains" + in: + arr: [3, 2, 1, 1] + k: 3 + out: 1 + - name: "strictly_descending_even" + in: + arr: [20, 18, 16, 14, 12, 10, 8, 6] + k: 2 + out: 6 + - name: "repeated_plateaus" + in: + arr: [4, 4, 3, 3, 2, 2, 1, 1] + k: 1 + out: 6 + - name: "three_chains_one_bad" + in: + arr: [1, 1, 1, 2, 1, 1, 2, 2, 2] + k: 3 + out: 0 + - name: "alternating_extremes" + in: + arr: [100, 1, 100, 1, 100, 1, 100] + k: 1 + out: 3 + - name: "near_limit_generated_a" + seed: 211101 + in: + arr: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 1000000000 + distinct: false + sorted: false + elemType: "int" + k: 1 + - name: "near_limit_generated_b" + seed: 211102 + in: + arr: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 1000000000 + distinct: false + sorted: false + elemType: "int" + k: 997 + - name: "large_sorted" + in: + arr: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 1000000000 + distinct: false + sorted: true + elemType: "int" + k: 49999 + - name: "large_constant" + in: + arr: + gen: "array" + len: 80000 + of: + gen: "int" + min: 777777777 + max: 777777777 + distinct: false + sorted: false + elemType: "int" + k: 40000 diff --git a/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/sol.py b/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/sol.py new file mode 100644 index 00000000..ef467c80 --- /dev/null +++ b/tests/2001-2500/2111. minimum-operations-to-make-the-array-k-increasing/sol.py @@ -0,0 +1,18 @@ +class Solution: + def kIncreasing(self, arr: List[int], k: int) -> int: + + n = len(arr) + keep = 0 + + for i in range(k): + g = [] + for j in range(i, n, k): + x = arr[j] + idx = bisect_right(g, x) + if idx == len(g): + g.append(x) + else: + g[idx] = x + keep += len(g) + + return n - keep \ No newline at end of file diff --git a/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/manifest.yaml b/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/manifest.yaml new file mode 100644 index 00000000..db5e0ee4 --- /dev/null +++ b/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/manifest.yaml @@ -0,0 +1,220 @@ +entry: + id: 2114 + title: "maximum-number-of-words-found-in-sentences" + params: + sentences: + type: array + items: + type: string + call: + cpp: "Solution().mostWordsFound({sentences})" + rust: "Solution::most_words_found({sentences})" + python3: "Solution().mostWordsFound({sentences})" + python2: "Solution().mostWordsFound({sentences})" + ruby: "most_words_found({sentences})" + java: "new Solution().mostWordsFound({sentences})" + csharp: "new Solution().MostWordsFound({sentences})" + kotlin: "Solution().mostWordsFound({sentences})" + go: "mostWordsFound({sentences})" + dart: "Solution().mostWordsFound({sentences})" + swift: "Solution().mostWordsFound({sentences})" + typescript: "mostWordsFound({sentences})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 128 +oracle: + python3: + call: "Checker().mostWordsFound(sentences, {result})" + checker: | + class Checker: + def mostWordsFound(self, sentences, result): + return isinstance(result, int) and result == max(s.count(' ') + 1 for s in sentences) +seed: 2114 +tests: + - name: "example-one" + in: + sentences: ["alice and bob love leetcode", "i think so too", "this is great thanks very much"] + out: 6 + - name: "example-two" + in: + sentences: ["please wait", "continue to fight", "continue to win"] + out: 3 + - name: "single-word" + in: + sentences: ["leetcode"] + out: 1 + - name: "single-long-sentence" + in: + sentences: ["a b c d e f g h i j"] + out: 10 + - name: "equal-counts" + in: + sentences: ["a b", "c d", "e f"] + out: 2 + - name: "first-is-longest" + in: + sentences: ["one two three four", "x", "y z"] + out: 4 + - name: "last-is-longest" + in: + sentences: ["x", "a b", "one two three four five"] + out: 5 + - name: "mixed-lengths" + in: + sentences: ["a", "a b c", "a b", "a b c d"] + out: 4 + - name: "many-single-words" + in: + sentences: ["a", "b", "c", "d", "e"] + out: 1 + - name: "spaces-count-words" + in: + sentences: ["ab cd ef gh", "i j k", "l m"] + out: 4 + - name: "hundred-one-word-sentences" + in: + sentences: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] + out: 1 + - name: "nine-words" + in: + sentences: ["a b c d e f g h i", "j k"] + out: 9 + - name: "word-length-irrelevant" + in: + sentences: ["longword", "x y z", "verylongword anotherlongword"] + out: 3 + - name: "short-words" + in: + sentences: ["a b c d e", "f g h i", "j"] + out: 5 + - name: "two-sentences" + in: + sentences: ["one two", "three four five"] + out: 3 + - name: "repeated-words" + in: + sentences: ["a a a a", "b b b"] + out: 4 + - name: "alphabet-words" + in: + sentences: ["aa bb cc dd ee ff", "gg hh"] + out: 6 + - name: "twenty-words" + in: + sentences: ["a b c d e f g h i j k l m n o p q r s t"] + out: 20 + - name: "longest-tie" + in: + sentences: ["a b c d", "e f g h", "i j"] + out: 4 + - name: "near-limit-string" + in: + sentences: ["a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a"] + out: 50 + - name: "generated-single-word-array" + seed: 1 + in: + sentences: + gen: "array" + len: 100 + of: + gen: "str" + len: 100 + alphabet: "a" + distinct: false + sorted: false + elemType: "string" + - name: "generated-small-single-words" + seed: 2 + in: + sentences: + gen: "array" + len: 20 + of: + gen: "str" + len: 1 + alphabet: "ab" + distinct: false + sorted: false + elemType: "string" + - name: "generated-max-sentences" + seed: 3 + in: + sentences: + gen: "array" + len: 100 + of: + gen: "str" + len: 99 + alphabet: "z" + distinct: false + sorted: false + elemType: "string" + - name: "generated-medium-single-words" + seed: 4 + in: + sentences: + gen: "array" + len: 60 + of: + gen: "str" + len: 50 + alphabet: "qw" + distinct: false + sorted: false + elemType: "string" + - name: "generated-minimal" + seed: 5 + in: + sentences: + gen: "array" + len: 1 + of: + gen: "str" + len: 100 + alphabet: "x" + distinct: false + sorted: false + elemType: "string" + - name: "five-words-middle" + in: + sentences: ["a b", "c d e f g", "h i j"] + out: 5 + - name: "seven-words" + in: + sentences: ["a b c d e f g", "h"] + out: 7 + - name: "six-words-last" + in: + sentences: ["a", "b c", "d e f g h i"] + out: 6 + - name: "three-words-only" + in: + sentences: ["red green blue", "one two"] + out: 3 + - name: "fourteen-words" + in: + sentences: ["a b c d e f g h i j k l m n"] + out: 14 + - name: "one-and-two" + in: + sentences: ["x", "y z"] + out: 2 + - name: "eight-words" + in: + sentences: ["a b c d e f g h", "i j k"] + out: 8 + - name: "thirty-words" + in: + sentences: ["a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d"] + out: 30 + - name: "single-character-sentences" + in: + sentences: ["a", "b c d e f", "g h"] + out: 5 + - name: "max-at-start" + in: + sentences: ["a b c d e f", "g h i", "j k l m"] + out: 6 diff --git a/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/sol.py b/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/sol.py new file mode 100644 index 00000000..c63ccc1e --- /dev/null +++ b/tests/2001-2500/2114. maximum-number-of-words-found-in-sentences/sol.py @@ -0,0 +1,8 @@ +class Solution: + def mostWordsFound(self, sentences: List[str]) -> int: + total = 0 + for ele in sentences: + if len(ele.split())>total: + total = len(ele.split()) + + return total \ No newline at end of file diff --git a/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/manifest.yaml b/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/manifest.yaml new file mode 100644 index 00000000..7f9c116a --- /dev/null +++ b/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/manifest.yaml @@ -0,0 +1,379 @@ +entry: + id: 2115 + title: "find-all-possible-recipes-from-given-supplies" + params: + recipes: + type: array + items: + type: string + ingredients: + type: array + items: + type: array + items: + type: string + supplies: + type: array + items: + type: string + call: + cpp: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + rust: "Solution::find_all_recipes({recipes}, {ingredients}, {supplies})" + python3: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + python2: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + ruby: "find_all_recipes({recipes}, {ingredients}, {supplies})" + java: "new Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + csharp: "new Solution().FindAllRecipes({recipes}, {ingredients}, {supplies})" + kotlin: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + go: "findAllRecipes({recipes}, {ingredients}, {supplies})" + dart: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + swift: "Solution().findAllRecipes({recipes}, {ingredients}, {supplies})" + typescript: "findAllRecipes({recipes}, {ingredients}, {supplies})" + +judge: + type: "ignore_order" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().findAllRecipes(recipes, ingredients, supplies, {result})" + checker: | + class Checker: + def findAllRecipes(self, recipes, ingredients, supplies, result): + if not isinstance(result, list) or len(result) != len(set(result)): + return False + recipe_set = set(recipes) + if any(x not in recipe_set for x in result): + return False + available = set(supplies) + remaining = {r: set(ingredients[i]) for i, r in enumerate(recipes)} + changed = True + expected = set() + while changed: + changed = False + for r in recipes: + if r not in expected and remaining[r] <= available: + expected.add(r) + available.add(r) + changed = True + return set(result) == expected + +seed: 2115 + +tests: + - name: "example_bread" + in: + recipes: ["bread"] + ingredients: + - ["yeast", "flour"] + supplies: ["yeast", "flour", "corn"] + out: ["bread"] + - name: "example_sandwich" + in: + recipes: ["bread", "sandwich"] + ingredients: + - ["yeast", "flour"] + - ["bread", "meat"] + supplies: ["yeast", "flour", "meat"] + out: ["bread", "sandwich"] + - name: "example_burger" + in: + recipes: ["bread", "sandwich", "burger"] + ingredients: + - ["yeast", "flour"] + - ["bread", "meat"] + - ["sandwich", "meat", "bread"] + supplies: ["yeast", "flour", "meat"] + out: ["bread", "sandwich", "burger"] + - name: "single_missing" + in: + recipes: ["cake"] + ingredients: + - ["flour"] + supplies: ["sugar"] + - name: "single_ready" + in: + recipes: ["tea"] + ingredients: + - ["water"] + supplies: ["water"] + - name: "three_independent" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["x"] + - ["y", "z"] + - ["q"] + supplies: ["x", "y", "z", "q"] + - name: "none_of_three" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["x"] + - ["y"] + - ["z"] + supplies: ["q"] + - name: "long_chain_four" + in: + recipes: ["r1", "r2", "r3", "r4"] + ingredients: + - ["s"] + - ["r1"] + - ["r2"] + - ["r3", "s"] + supplies: ["s"] + - name: "reverse_chain_order" + in: + recipes: ["z", "y", "x"] + ingredients: + - ["y"] + - ["x"] + - ["raw"] + supplies: ["raw"] + - name: "branching_dag" + in: + recipes: ["base", "left", "right", "top"] + ingredients: + - ["raw"] + - ["base", "salt"] + - ["base", "pepper"] + - ["left", "right"] + supplies: ["raw", "salt", "pepper"] + - name: "cycle_two_unseeded" + in: + recipes: ["a", "b"] + ingredients: + - ["b"] + - ["a"] + supplies: ["x"] + - name: "cycle_with_branch" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["b"] + - ["a"] + - ["a", "raw"] + supplies: ["raw"] + - name: "cycle_broken_by_raw" + in: + recipes: ["a", "b"] + ingredients: + - ["b", "raw"] + - ["a", "raw"] + supplies: ["raw"] + - name: "multiple_prerequisites" + in: + recipes: ["meal", "sauce"] + ingredients: + - ["sauce", "bread", "fruit"] + - ["tomato", "oil"] + supplies: ["tomato", "oil", "bread", "fruit"] + - name: "irrelevant_supplies" + in: + recipes: ["a", "b"] + ingredients: + - ["x"] + - ["a", "y"] + supplies: ["x", "y", "unused1", "unused2"] + - name: "shared_prerequisite" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["raw"] + - ["raw"] + - ["a", "b"] + supplies: ["raw"] + - name: "recipe_named_like_external" + in: + recipes: ["ab", "cd"] + ingredients: + - ["a"] + - ["ab", "c"] + supplies: ["a", "c"] + - name: "all_single_ingredients" + in: + recipes: ["a", "b", "c", "d", "e"] + ingredients: + - ["s1"] + - ["s2"] + - ["s3"] + - ["s4"] + - ["s5"] + supplies: ["s1", "s2", "s3", "s4", "s5"] + - name: "one_missing_in_chain" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["raw"] + - ["a", "missing"] + - ["b"] + supplies: ["raw"] + - name: "deep_two_inputs" + in: + recipes: ["a", "b", "c", "d", "e"] + ingredients: + - ["x", "y"] + - ["a", "z"] + - ["b", "q"] + - ["c", "r"] + - ["d", "s"] + supplies: ["x", "y", "z", "q", "r", "s"] + - name: "late_unlock" + in: + recipes: ["top", "mid", "base"] + ingredients: + - ["mid"] + - ["base"] + - ["raw"] + supplies: ["raw"] + - name: "unreachable_side_branch" + in: + recipes: ["a", "b", "c", "d"] + ingredients: + - ["raw"] + - ["unknown"] + - ["a", "b"] + - ["c"] + supplies: ["raw"] + - name: "two_components" + in: + recipes: ["a", "b", "c", "d"] + ingredients: + - ["x"] + - ["a"] + - ["y"] + - ["c", "z"] + supplies: ["x", "y", "z"] + - name: "all_recipe_dependencies" + in: + recipes: ["r1", "r2", "r3"] + ingredients: + - ["raw1"] + - ["r1"] + - ["r2"] + supplies: ["raw1"] + - name: "blocked_extra_ingredient" + in: + recipes: ["a", "b"] + ingredients: + - ["raw", "nope"] + - ["a"] + supplies: ["raw"] + - name: "four_way_top" + in: + recipes: ["a", "b", "c", "d", "top"] + ingredients: + - ["x"] + - ["y"] + - ["z"] + - ["w"] + - ["a", "b", "c", "d"] + supplies: ["x", "y", "z", "w"] + - name: "cycle_and_independent" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["b"] + - ["a"] + - ["raw"] + supplies: ["raw"] + - name: "chain_with_decoy" + in: + recipes: ["a", "b", "c", "decoy"] + ingredients: + - ["raw"] + - ["a"] + - ["b"] + - ["notavailable"] + supplies: ["raw", "extra"] + - name: "many_supplies" + in: + recipes: ["a", "b"] + ingredients: + - ["s1", "s2", "s3"] + - ["a", "s4", "s5"] + supplies: ["s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8"] + - name: "single_missing_of_many" + in: + recipes: ["a"] + ingredients: + - ["s1", "s2", "s3", "s4"] + supplies: ["s1", "s2", "s3"] + - name: "dependency_used_twice" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["raw"] + - ["a", "raw"] + - ["a", "b"] + supplies: ["raw"] + - name: "cycle_with_downstream" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["b"] + - ["a"] + - ["b"] + supplies: ["raw"] + - name: "two_ready_one_dependent" + in: + recipes: ["a", "b", "c"] + ingredients: + - ["x"] + - ["y"] + - ["a", "b"] + supplies: ["x", "y"] + - name: "blocked_cycle_with_ready" + in: + recipes: ["a", "b", "c", "d"] + ingredients: + - ["b"] + - ["a"] + - ["raw"] + - ["c", "unknown"] + supplies: ["raw"] + - name: "longer_branching" + in: + recipes: ["a", "b", "c", "d", "e", "f"] + ingredients: + - ["x"] + - ["x"] + - ["a", "b"] + - ["c", "y"] + - ["c", "z"] + - ["d", "e"] + supplies: ["x", "y", "z"] + - name: "single_long_name" + in: + recipes: ["abcdefghij"] + ingredients: + - ["klmnopqrst"] + supplies: ["klmnopqrst"] + - name: "stress_chain_100" + in: + recipes: ["r001", "r002", "r003", "r004", "r005", "r006", "r007", "r008", "r009", "r010", "r011", "r012", "r013", "r014", "r015", "r016", "r017", "r018", "r019", "r020"] + ingredients: + - ["raw"] + - ["r001"] + - ["r002"] + - ["r003"] + - ["r004"] + - ["r005"] + - ["r006"] + - ["r007"] + - ["r008"] + - ["r009"] + - ["r010"] + - ["r011"] + - ["r012"] + - ["r013"] + - ["r014"] + - ["r015"] + - ["r016"] + - ["r017"] + - ["r018"] + - ["r019"] + supplies: ["raw"] diff --git a/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/sol.py b/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/sol.py new file mode 100644 index 00000000..8c36d6a1 --- /dev/null +++ b/tests/2001-2500/2115. find-all-possible-recipes-from-given-supplies/sol.py @@ -0,0 +1,37 @@ +class Solution: + def findAllRecipes(self, recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]: + available_supplies = set(supplies) + + ingredient_to_recipes = {} + + in_degree = {} + + recipe_to_ingredients = {} + + for i, recipe in enumerate(recipes): + recipe_ingredients = ingredients[i] + recipe_to_ingredients[recipe] = recipe_ingredients + in_degree[recipe] = len(recipe_ingredients) + + for ingredient in recipe_ingredients: + if ingredient not in ingredient_to_recipes: + ingredient_to_recipes[ingredient] = [] + ingredient_to_recipes[ingredient].append(recipe) + + queue = list(available_supplies) + result = [] + + while queue: + current = queue.pop(0) + + if current in recipe_to_ingredients: + result.append(current) + + if current in ingredient_to_recipes: + for dependent_recipe in ingredient_to_recipes[current]: + in_degree[dependent_recipe] -= 1 + + if in_degree[dependent_recipe] == 0: + queue.append(dependent_recipe) + + return result \ No newline at end of file diff --git a/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/manifest.yaml b/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/manifest.yaml new file mode 100644 index 00000000..bc4fff0c --- /dev/null +++ b/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/manifest.yaml @@ -0,0 +1,256 @@ +entry: + id: 2116 + title: "check-if-a-parentheses-string-can-be-valid" + params: + s: + type: string + locked: + type: string + call: + cpp: "Solution().canBeValid({s}, {locked})" + rust: "Solution::can_be_valid({s}, {locked})" + python3: "Solution().canBeValid({s}, {locked})" + python2: "Solution().canBeValid({s}, {locked})" + ruby: "can_be_valid({s}, {locked})" + java: "new Solution().canBeValid({s}, {locked})" + csharp: "new Solution().CanBeValid({s}, {locked})" + kotlin: "Solution().canBeValid({s}, {locked})" + go: "canBeValid({s}, {locked})" + dart: "Solution().canBeValid({s}, {locked})" + swift: "Solution().canBeValid({s}, {locked})" + typescript: "canBeValid({s}, {locked})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().canBeValid(s, locked, {result})" + checker: | + class Checker: + def canBeValid(self, s, locked, result): + if not isinstance(result, bool) or len(s) != len(locked) or len(s) % 2: + return False + lo = hi = 0 + for ch, flag in zip(s, locked): + if flag == '0': + lo -= 1 + hi += 1 + elif ch == '(': + lo += 1 + hi += 1 + else: + lo -= 1 + hi -= 1 + if hi < 0: + return False + lo = max(lo, 0) + return result == (lo == 0) + +seed: 21162026 + +tests: + - name: "example_1" + in: + s: "))()))" + locked: "010100" + out: true + - name: "example_2" + in: + s: "()()" + locked: "0000" + out: true + - name: "example_3_odd" + in: + s: ")" + locked: "0" + out: false + - name: "single_open_unlocked" + in: + s: "(" + locked: "0" + out: false + - name: "single_close_locked" + in: + s: ")" + locked: "1" + out: false + - name: "pair_already_valid_locked" + in: + s: "()" + locked: "11" + out: true + - name: "pair_reversed_locked" + in: + s: ")(" + locked: "11" + out: false + - name: "pair_reversed_unlocked" + in: + s: ")(" + locked: "00" + out: true + - name: "all_open_locked" + in: + s: "((((" + locked: "1111" + out: false + - name: "all_close_locked" + in: + s: "))))" + locked: "1111" + out: false + - name: "all_open_unlocked" + in: + s: "((((" + locked: "0000" + out: true + - name: "all_close_unlocked" + in: + s: "))))" + locked: "0000" + out: true + - name: "locked_prefix_close" + in: + s: ")())" + locked: "1000" + out: false + - name: "unlocked_prefix_rescue" + in: + s: ")())" + locked: "0000" + out: true + - name: "locked_suffix_open" + in: + s: "((()" + locked: "0001" + out: true + - name: "unlocked_suffix_rescue" + in: + s: "((()" + locked: "0000" + out: true + - name: "odd_length_mixed" + in: + s: "(()))" + locked: "01010" + out: false + - name: "balanced_mixed_locks" + in: + s: "(()())" + locked: "101010" + out: true + - name: "unlocked_middle_only" + in: + s: "()))(" + locked: "11011" + out: false + - name: "two_unlocked_middle" + in: + s: "()))(" + locked: "11001" + out: false + - name: "alternating_locked_valid" + in: + s: "()()()()" + locked: "10101010" + out: true + - name: "alternating_locked_invalid" + in: + s: ")()()()(" + locked: "10101010" + out: false + - name: "late_unlocked_open" + in: + s: "))))((" + locked: "111100" + out: false + - name: "early_unlocked_open" + in: + s: "))))((" + locked: "000011" + out: false + - name: "one_change_needed" + in: + s: ")()(" + locked: "1001" + out: false + - name: "two_changes_needed" + in: + s: "))((" + locked: "0000" + out: true + - name: "fixed_valid_nested" + in: + s: "((()))" + locked: "111111" + out: true + - name: "fixed_invalid_nested" + in: + s: "(())))" + locked: "111111" + out: false + - name: "odd_all_unlocked" + in: + s: "()()()()()" + locked: "0000000000" + out: true + - name: "long_even_valid" + in: + s: "()()()()()()()()()()()()()()()()" + locked: "11111111111111111111111111111111" + out: true + - name: "long_even_invalid" + in: + s: "((((((((((((((((" + locked: "1111111111111111" + out: false + - name: "long_unlocked_repair" + in: + s: "))))))))))))))))" + locked: "0000000000000000" + out: true + - name: "odd_long_unlocked" + in: + s: ")))))))))))))))" + locked: "000000000000000" + out: false + - name: "locked_balance_with_free_pair" + in: + s: "())(()" + locked: "110011" + out: true + - name: "locked_balance_wrong_order" + in: + s: ")(()())(" + locked: "10000001" + out: false + - name: "deep_valid_fixed" + in: + s: "()()()()()()()()()()()()()()()()()()()()" + locked: "1111111111111111111111111111111111111111" + out: true + - name: "deep_invalid_fixed" + in: + s: "((((((((((((((((((((((((((((((((((((((((" + locked: "1111111111111111111111111111111111111111" + out: false + - name: "deep_unlocked_repair" + in: + s: "))))))))))))))))))))))))))))))))))))))))" + locked: "0000000000000000000000000000000000000000" + out: true + - name: "mixed_locked_valid_long" + in: + s: "(()())()()((()))()()(()())()()((()))()()" + locked: "1010101010101010101010101010101010101010" + out: true + - name: "mixed_locked_invalid_long" + in: + s: "))))))(((()))))(((()))))(((()))))(((())))" + locked: "1111110000111111000011111100001111110000" + out: false diff --git a/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/sol.py b/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/sol.py new file mode 100644 index 00000000..8f14a174 --- /dev/null +++ b/tests/2001-2500/2116. check-if-a-parentheses-string-can-be-valid/sol.py @@ -0,0 +1,25 @@ +class Solution: + def canBeValid(self, s: str, locked: str) -> bool: + n = len(s) + if n % 2 != 0: + return False + + open_count = 0 + for i in range(n): + if s[i] == '(' or locked[i] == '0': + open_count += 1 + else: + open_count -= 1 + if open_count < 0: + return False + + close_count = 0 + for i in range(n - 1, -1, -1): + if s[i] == ')' or locked[i] == '0': + close_count += 1 + else: + close_count -= 1 + if close_count < 0: + return False + + return True \ No newline at end of file diff --git a/tests/2001-2500/2117. abbreviating-the-product-of-a-range/manifest.yaml b/tests/2001-2500/2117. abbreviating-the-product-of-a-range/manifest.yaml new file mode 100644 index 00000000..fdb78c70 --- /dev/null +++ b/tests/2001-2500/2117. abbreviating-the-product-of-a-range/manifest.yaml @@ -0,0 +1,237 @@ +entry: + id: 2117 + title: "abbreviating-the-product-of-a-range" + params: + left: + type: int + right: + type: int + call: + cpp: "Solution().abbreviateProduct({left}, {right})" + rust: "Solution::abbreviate_product({left}, {right})" + python3: "Solution().abbreviateProduct({left}, {right})" + python2: "Solution().abbreviateProduct({left}, {right})" + ruby: "abbreviate_product({left}, {right})" + java: "new Solution().abbreviateProduct({left}, {right})" + csharp: "new Solution().AbbreviateProduct({left}, {right})" + kotlin: "Solution().abbreviateProduct({left}, {right})" + go: "abbreviateProduct({left}, {right})" + dart: "Solution().abbreviateProduct({left}, {right})" + swift: "Solution().abbreviateProduct({left}, {right})" + typescript: "abbreviateProduct({left}, {right})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().abbreviateProduct(left, right, {result})" + checker: | + class Checker: + def abbreviateProduct(self, left, right, result): + if not isinstance(result, str): + return False + product = 1 + for value in range(left, right + 1): + product *= value + zeros = 0 + while product % 10 == 0: + product //= 10 + zeros += 1 + digits = str(product) + if len(digits) > 10: + digits = digits[:5] + '...' + digits[-5:] + return result == digits + 'e' + str(zeros) + +seed: 2117 + +tests: + - name: "case_01_1_1" + in: + left: 1 + right: 1 + out: '"1e0"' + - name: "case_02_2_2" + in: + left: 2 + right: 2 + out: '"2e0"' + - name: "case_03_5_5" + in: + left: 5 + right: 5 + out: '"5e0"' + - name: "case_04_10_10" + in: + left: 10 + right: 10 + out: '"1e1"' + - name: "case_05_11_11" + in: + left: 11 + right: 11 + out: '"11e0"' + - name: "case_06_1_2" + in: + left: 1 + right: 2 + out: '"2e0"' + - name: "case_07_1_4" + in: + left: 1 + right: 4 + out: '"24e0"' + - name: "case_08_2_11" + in: + left: 2 + right: 11 + out: '"399168e2"' + - name: "case_09_3_7" + in: + left: 3 + right: 7 + out: '"252e1"' + - name: "case_10_8_12" + in: + left: 8 + right: 12 + out: '"9504e1"' + - name: "case_11_10_20" + in: + left: 10 + right: 20 + out: '"6704425728e3"' + - name: "case_12_20_25" + in: + left: 20 + right: 25 + out: '"127512e3"' + - name: "case_13_25_30" + in: + left: 25 + right: 30 + out: '"427518e3"' + - name: "case_14_50_55" + in: + left: 50 + right: 55 + out: '"20872566e3"' + - name: "case_15_99_100" + in: + left: 99 + right: 100 + out: '"99e2"' + - name: "case_16_100_105" + in: + left: 100 + right: 105 + out: '"1158727752e3"' + - name: "case_17_1_10" + in: + left: 1 + right: 10 + out: '"36288e2"' + - name: "case_18_1_11" + in: + left: 1 + right: 11 + out: '"399168e2"' + - name: "case_19_2_20" + in: + left: 2 + right: 20 + out: '"24329...17664e4"' + - name: "case_20_5_15" + in: + left: 5 + right: 15 + out: '"54486432e3"' + - name: "case_21_10_30" + in: + left: 10 + right: 30 + out: '"73096...14496e6"' + - name: "case_22_37_42" + in: + left: 37 + right: 42 + out: '"377696592e1"' + - name: "case_23_99_111" + in: + left: 99 + right: 111 + out: '"18701...60192e4"' + - name: "case_24_371_375" + in: + left: 371 + right: 375 + out: '"7219856259e3"' + - name: "case_25_500_510" + in: + left: 500 + right: 510 + out: '"54464...59744e5"' + - name: "case_26_999_1001" + in: + left: 999 + right: 1001 + out: '"999999e3"' + - name: "case_27_1000_1010" + in: + left: 1000 + right: 1010 + out: '"10563...82688e5"' + - name: "case_28_1234_1240" + in: + left: 1234 + right: 1240 + out: '"44318...63424e2"' + - name: "case_29_2000_2010" + in: + left: 2000 + right: 2010 + out: '"21050...98176e5"' + - name: "case_30_4096_4100" + in: + left: 4096 + right: 4100 + out: '"11557...45984e2"' + - name: "case_31_8000_8010" + in: + left: 8000 + right: 8010 + out: '"86491...39904e5"' + - name: "case_32_9990_10000" + in: + left: 9990 + right: 10000 + out: '"99451...72288e6"' + - name: "case_33_1_100" + in: + left: 1 + right: 100 + out: '"93326...16864e24"' + - name: "case_34_1_500" + in: + left: 1 + right: 500 + out: '"12201...12864e124"' + - name: "case_35_100_1000" + in: + left: 100 + right: 1000 + out: '"43116...46048e227"' + - name: "case_36_5000_6000" + in: + left: 5000 + right: 6000 + out: '"31736...43584e253"' + - name: "case_37_9000_10000" + in: + left: 9000 + right: 10000 + out: '"31626...93632e254"' diff --git a/tests/2001-2500/2117. abbreviating-the-product-of-a-range/sol.py b/tests/2001-2500/2117. abbreviating-the-product-of-a-range/sol.py new file mode 100644 index 00000000..ffebfb6e --- /dev/null +++ b/tests/2001-2500/2117. abbreviating-the-product-of-a-range/sol.py @@ -0,0 +1,46 @@ +import math + +class Solution: + def abbreviateProduct(self, left: int, right: int) -> str: + last = 1 + modulo = 10 ** 5 + + twosCount = 0 + fivesCount = 0 + + sumLog10 = 0 + maxBufferValue = 10 ** 1200 + bufferProduct = 1 + + for x in range(left, right + 1): + bufferProduct *= x + + if bufferProduct > maxBufferValue: + sumLog10 += math.log10(bufferProduct) + bufferProduct = 1 + + while x % 2 == 0: + twosCount += 1 + x //= 2 + + while x % 5 == 0: + fivesCount += 1 + x //= 5 + + last = (last * x) % modulo + + sumLog10 += math.log10(bufferProduct) + zerosCount = min(twosCount, fivesCount) + + if sumLog10 < 10 + zerosCount: + productString = str(bufferProduct) + return productString[:len(productString) - zerosCount] + 'e' + str(zerosCount) + + twosCount -= zerosCount + fivesCount -= zerosCount + + last = (last * (pow(2, twosCount) % modulo)) % modulo + last = (last * (pow(5, fivesCount) % modulo)) % modulo + first = int(pow(10, sumLog10 % 1 + 4.0)) + + return str(first) + '...' + str(last).zfill(5) + 'e' + str(zerosCount) diff --git a/tests/2001-2500/2119. a-number-after-a-double-reversal/manifest.yaml b/tests/2001-2500/2119. a-number-after-a-double-reversal/manifest.yaml new file mode 100644 index 00000000..41c6194d --- /dev/null +++ b/tests/2001-2500/2119. a-number-after-a-double-reversal/manifest.yaml @@ -0,0 +1,210 @@ +entry: + id: 2119 + title: "a-number-after-a-double-reversal" + params: + num: + type: int + call: + cpp: "Solution().isSameAfterReversals({num})" + rust: "Solution::is_same_after_reversals({num})" + python3: "Solution().isSameAfterReversals({num})" + python2: "Solution().isSameAfterReversals({num})" + ruby: "is_same_after_reversals({num})" + java: "new Solution().isSameAfterReversals({num})" + csharp: "new Solution().IsSameAfterReversals({num})" + kotlin: "Solution().isSameAfterReversals({num})" + go: "isSameAfterReversals({num})" + dart: "Solution().isSameAfterReversals({num})" + swift: "Solution().isSameAfterReversals({num})" + typescript: "isSameAfterReversals({num})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().isSameAfterReversals(num, {result})" + checker: | + class Checker: + def isSameAfterReversals(self, num, result): + expected = (num == 0 or num % 10 != 0) + return result is expected + +seed: 2119 + +tests: + - name: "example_1" + in: + num: 526 + out: true + - name: "example_2" + in: + num: 1800 + out: false + - name: "example_3_zero" + in: + num: 0 + out: true + - name: "one_digit_one" + in: + num: 1 + out: true + - name: "one_digit_nine" + in: + num: 9 + out: true + - name: "ten" + in: + num: 10 + out: false + - name: "eleven" + in: + num: 11 + out: true + - name: "ninety" + in: + num: 90 + out: false + - name: "ninety_one" + in: + num: 91 + out: true + - name: "one_hundred" + in: + num: 100 + out: false + - name: "one_hundred_one" + in: + num: 101 + out: true + - name: "one_hundred_ten" + in: + num: 110 + out: false + - name: "one_hundred_eleven" + in: + num: 111 + out: true + - name: "leading_zero_after_reverse" + in: + num: 1200 + out: false + - name: "internal_zero" + in: + num: 2021 + out: true + - name: "trailing_single_zero" + in: + num: 1230 + out: false + - name: "trailing_zero_nonzero_prefix" + in: + num: 1001 + out: true + - name: "four_digit_palindrome" + in: + num: 1221 + out: true + - name: "four_digit_nonzero" + in: + num: 9876 + out: true + - name: "four_digit_trailing_zero" + in: + num: 9870 + out: false + - name: "five_digit_small" + in: + num: 10000 + out: false + - name: "five_digit_no_zero" + in: + num: 12345 + out: true + - name: "five_digit_internal_zeros" + in: + num: 10001 + out: true + - name: "five_digit_end_zero" + in: + num: 54320 + out: false + - name: "six_digit_min" + in: + num: 100000 + out: false + - name: "six_digit_no_zero" + in: + num: 654321 + out: true + - name: "six_digit_internal_zero" + in: + num: 600006 + out: true + - name: "six_digit_multiple_trailing_zero" + in: + num: 700000 + out: false + - name: "upper_boundary" + in: + num: 1000000 + out: false + - name: "near_upper_boundary" + in: + num: 999999 + out: true + - name: "near_upper_with_zero" + in: + num: 999990 + out: false + - name: "alternating_digits" + in: + num: 909090 + out: false + - name: "zero_middle" + in: + num: 90809 + out: true + - name: "maximum_without_trailing_zero" + in: + num: 999999 + out: true + - name: "generated_small" + seed: 1 + in: + num: + gen: "int" + min: 0 + max: 9 + - name: "generated_full_range" + seed: 2 + in: + num: + gen: "int" + min: 0 + max: 1000000 + - name: "generated_trailing_zero_range" + seed: 3 + in: + num: + gen: "int" + min: 10 + max: 100000 + - name: "generated_mid_range" + seed: 4 + in: + num: + gen: "int" + min: 100000 + max: 999999 + - name: "generated_upper_range" + seed: 5 + in: + num: + gen: "int" + min: 999900 + max: 1000000 diff --git a/tests/2001-2500/2119. a-number-after-a-double-reversal/sol.py b/tests/2001-2500/2119. a-number-after-a-double-reversal/sol.py new file mode 100644 index 00000000..64d54cbb --- /dev/null +++ b/tests/2001-2500/2119. a-number-after-a-double-reversal/sol.py @@ -0,0 +1,11 @@ +class Solution: + def reverse(self, num: int) -> int: + temp = num + rem = 0 + while temp > 0: + rem = rem * 10 + temp % 10 + temp //= 10 + return rem + + def isSameAfterReversals(self, num: int) -> bool: + return self.reverse(self.reverse(num)) == num \ No newline at end of file diff --git a/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/manifest.yaml b/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/manifest.yaml new file mode 100644 index 00000000..6790b21d --- /dev/null +++ b/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/manifest.yaml @@ -0,0 +1,283 @@ +entry: + id: 2120 + title: "execution-of-all-suffix-instructions-staying-in-a-grid" + params: + n: + type: int + startPos: + type: array + items: + type: int + s: + type: string + call: + cpp: "Solution().executeInstructions({n}, {startPos}, {s})" + rust: "Solution::execute_instructions({n}, {startPos}, {s})" + python3: "Solution().executeInstructions({n}, {startPos}, {s})" + python2: "Solution().executeInstructions({n}, {startPos}, {s})" + ruby: "execute_instructions({n}, {startPos}, {s})" + java: "new Solution().executeInstructions({n}, {startPos}, {s})" + csharp: "new Solution().ExecuteInstructions({n}, {startPos}, {s})" + kotlin: "Solution().executeInstructions({n}, {startPos}, {s})" + go: "executeInstructions({n}, {startPos}, {s})" + dart: "Solution().executeInstructions({n}, {startPos}, {s})" + swift: "Solution().executeInstructions({n}, {startPos}, {s})" + typescript: "executeInstructions({n}, {startPos}, {s})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().executeInstructions(n, startPos, s, {result})" + checker: | + class Checker: + def executeInstructions(self, n, startPos, s, result): + if not isinstance(result, list) or len(result) != len(s): + return False + expected = [] + for i in range(len(s)): + row, col = startPos + count = 0 + for ch in s[i:]: + if ch == 'L': col -= 1 + elif ch == 'R': col += 1 + elif ch == 'U': row -= 1 + else: row += 1 + if not (0 <= row < n and 0 <= col < n): break + count += 1 + expected.append(count) + return result == expected + +seed: 212012 + +tests: + - name: "example_1" + in: + n: 3 + startPos: [0, 1] + s: "RRDDLU" + out: [1, 5, 4, 3, 1, 0] + - name: "example_2" + in: + n: 2 + startPos: [1, 1] + s: "LURD" + out: [4, 1, 0, 0] + - name: "example_3_single_cell" + in: + n: 1 + startPos: [0, 0] + s: "LRUD" + out: [0, 0, 0, 0] + - name: "corner_cycle" + in: + n: 2 + startPos: [0, 0] + s: "RDLU" + out: [4, 1, 0, 0] + - name: "bottom_left_cycle" + in: + n: 2 + startPos: [1, 0] + s: "URDL" + out: [4, 1, 0, 0] + - name: "center_cycle" + in: + n: 3 + startPos: [1, 1] + s: "LRUD" + out: [4, 3, 2, 1] + - name: "top_left_outward" + in: + n: 4 + startPos: [0, 0] + s: "RRDDLLUU" + out: [8, 4, 2, 1, 0, 0, 0, 0] + - name: "bottom_right_inward" + in: + n: 4 + startPos: [3, 3] + s: "LLUURRDD" + out: [8, 4, 2, 1, 0, 0, 0, 0] + - name: "center_square" + in: + n: 5 + startPos: [2, 2] + s: "RRDDLLUU" + out: [8, 7, 6, 5, 4, 3, 2, 1] + - name: "top_right_mixed" + in: + n: 5 + startPos: [0, 4] + s: "LDDRRU" + out: [4, 2, 1, 0, 0, 0] + - name: "long_turning_path" + in: + n: 6 + startPos: [3, 1] + s: "DURRULLD" + out: [8, 7, 6, 5, 2, 1, 2, 1] + - name: "left_edge_mixed" + in: + n: 3 + startPos: [1, 0] + s: "RDRUL" + out: [5, 4, 3, 1, 0] + - name: "bottom_right_mixed" + in: + n: 3 + startPos: [2, 2] + s: "ULDLR" + out: [5, 1, 0, 2, 0] + - name: "edge_start_down" + in: + n: 7 + startPos: [6, 0] + s: "URRDDL" + out: [4, 2, 1, 0, 0, 0] + - name: "edge_start_left" + in: + n: 8 + startPos: [0, 7] + s: "LDDRUUL" + out: [7, 2, 1, 0, 0, 0, 1] + - name: "long_center_path" + in: + n: 9 + startPos: [4, 4] + s: "RURDLULDR" + out: [9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "ten_grid_down_right" + in: + n: 10 + startPos: [5, 2] + s: "DDRRUULL" + out: [8, 7, 6, 5, 4, 3, 2, 1] + - name: "ten_grid_corner" + in: + n: 10 + startPos: [0, 0] + s: "DRDRULUL" + out: [8, 5, 4, 1, 0, 0, 0, 0] + - name: "eleven_grid_corner" + in: + n: 11 + startPos: [10, 10] + s: "ULULDRDR" + out: [8, 5, 4, 1, 0, 0, 0, 0] + - name: "repeated_horizontal" + in: + n: 12 + startPos: [6, 6] + s: "RRRRLLLLUUU" + out: [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "top_right_boundary" + in: + n: 13 + startPos: [1, 11] + s: "LLDDRRUU" + out: [8, 7, 3, 2, 1, 2, 1, 1] + - name: "bottom_left_boundary" + in: + n: 14 + startPos: [7, 0] + s: "UUURRDDDLLL" + out: [10, 9, 8, 7, 5, 3, 2, 1, 0, 0, 0] + - name: "top_right_long" + in: + n: 15 + startPos: [0, 14] + s: "DDDLLLUURRR" + out: [11, 10, 5, 3, 2, 1, 0, 0, 0, 0, 0] + - name: "alternating_center" + in: + n: 16 + startPos: [8, 8] + s: "LRLRUDUD" + out: [8, 7, 6, 5, 4, 3, 2, 1] + - name: "seventeen_mixed" + in: + n: 17 + startPos: [4, 12] + s: "RDLURDLU" + out: [8, 7, 6, 5, 4, 3, 2, 1] + - name: "eighteen_corner" + in: + n: 18 + startPos: [17, 0] + s: "URURDDLL" + out: [8, 4, 3, 1, 0, 0, 0, 0] + - name: "long_down_from_center" + in: + n: 19 + startPos: [9, 9] + s: "DDDDDDDDDD" + out: [9, 9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "long_right_from_corner" + in: + n: 20 + startPos: [0, 0] + s: "RRRRRRRRRR" + out: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "backtracking_vertical" + in: + n: 21 + startPos: [10, 10] + s: "UDUDUDUDUDUDUDUD" + out: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "large_balanced_square" + in: + n: 25 + startPos: [24, 24] + s: "ULULULULULUL" + out: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] + - name: "generated_small" + seed: 101 + in: + n: 5 + startPos: [2, 2] + s: + gen: "str" + len: 25 + alphabet: "LRUD" + - name: "generated_edge" + seed: 102 + in: + n: 2 + startPos: [0, 1] + s: + gen: "str" + len: 40 + alphabet: "LRUD" + - name: "generated_medium" + seed: 103 + in: + n: 17 + startPos: [8, 8] + s: + gen: "str" + len: 120 + alphabet: "LRUD" + - name: "generated_near_limit" + seed: 104 + in: + n: 250 + startPos: [125, 125] + s: + gen: "str" + len: 450 + alphabet: "LRUD" + - name: "generated_maximum" + seed: 105 + in: + n: 500 + startPos: [249, 250] + s: + gen: "str" + len: 500 + alphabet: "LRUD" diff --git a/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/sol.py b/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/sol.py new file mode 100644 index 00000000..114ab87a --- /dev/null +++ b/tests/2001-2500/2120. execution-of-all-suffix-instructions-staying-in-a-grid/sol.py @@ -0,0 +1,22 @@ +class Solution: + def executeInstructions(self, n, startPos, s): + m = len(s) + ans = [] + for i in range(m): + row, col = startPos + count = 0 + for j in range(i, m): + if s[j] == 'L': + col -= 1 + elif s[j] == 'R': + col += 1 + elif s[j] == 'U': + row -= 1 + else: + row += 1 + if 0 <= row < n and 0 <= col < n: + count += 1 + else: + break + ans.append(count) + return ans \ No newline at end of file diff --git a/tests/2001-2500/2121. intervals-between-identical-elements/manifest.yaml b/tests/2001-2500/2121. intervals-between-identical-elements/manifest.yaml new file mode 100644 index 00000000..12693865 --- /dev/null +++ b/tests/2001-2500/2121. intervals-between-identical-elements/manifest.yaml @@ -0,0 +1,241 @@ +entry: + id: 2121 + title: "intervals-between-identical-elements" + params: + arr: + type: array + items: + type: int + call: + cpp: "Solution().getDistances({arr})" + rust: "Solution::get_distances({arr})" + python3: "Solution().getDistances({arr})" + python2: "Solution().getDistances({arr})" + ruby: "get_distances({arr})" + java: "new Solution().getDistances({arr})" + csharp: "new Solution().GetDistances({arr})" + kotlin: "Solution().getDistances({arr})" + go: "getDistances({arr})" + dart: "Solution().getDistances({arr})" + swift: "Solution().getDistances({arr})" + typescript: "getDistances({arr})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().getDistances(arr, {result})" + checker: | + class Checker: + def getDistances(self, arr, result): + if not isinstance(result, list) or len(result) != len(arr): + return False + positions = {} + for i, value in enumerate(arr): + positions.setdefault(value, []).append(i) + expected = [0] * len(arr) + for indices in positions.values(): + for i in indices: + expected[i] = sum(abs(i - j) for j in indices) + return result == expected + +seed: 2121 + +tests: + - name: "example_1" + in: + arr: [2, 1, 3, 1, 2, 3, 3] + out: [4, 2, 7, 2, 4, 4, 5] + - name: "example_2" + in: + arr: [10, 5, 10, 10] + out: [5, 0, 3, 4] + - name: "single_element" + in: + arr: [1] + out: [0] + - name: "pair_equal" + in: + arr: [1, 1] + out: [1, 1] + - name: "all_unique" + in: + arr: [1, 2, 3, 4, 5] + out: [0, 0, 0, 0, 0] + - name: "three_equal" + in: + arr: [7, 7, 7] + out: [3, 2, 3] + - name: "one_duplicate" + in: + arr: [1, 2, 1] + out: [2, 0, 2] + - name: "symmetric_duplicates" + in: + arr: [1, 2, 3, 2, 1] + out: [4, 2, 0, 2, 4] + - name: "mixed_frequency" + in: + arr: [5, 1, 5, 2, 5, 1] + out: [6, 4, 4, 0, 6, 4] + - name: "maximum_values" + in: + arr: [100000, 1, 100000, 1, 100000] + out: [6, 2, 4, 2, 6] + - name: "adjacent_pairs" + in: + arr: [1, 1, 2, 2, 3, 3] + out: [1, 1, 1, 1, 1, 1] + - name: "alternating_two" + in: + arr: [1, 2, 1, 2, 1, 2] + out: [6, 6, 4, 4, 6, 6] + - name: "one_value_dominates" + in: + arr: [4, 4, 1, 4, 2, 4] + out: [9, 7, 0, 7, 0, 11] + - name: "unique_descending" + in: + arr: [9, 8, 7, 6, 5, 4, 3, 2, 1] + out: [0, 0, 0, 0, 0, 0, 0, 0, 0] + - name: "alternating_three" + in: + arr: [1, 3, 1, 3, 1, 3, 1] + out: [12, 6, 8, 4, 8, 6, 12] + - name: "duplicate_at_end" + in: + arr: [2, 2, 2, 1, 2] + out: [7, 5, 5, 0, 9] + - name: "large_values_alternating" + in: + arr: [1, 100000, 1, 100000, 1] + out: [6, 2, 4, 2, 6] + - name: "four_occurrences" + in: + arr: [6, 5, 6, 5, 6, 5, 6] + out: [12, 6, 8, 4, 8, 6, 12] + - name: "repeated_triplets" + in: + arr: [1, 2, 3, 1, 2, 3, 1, 2, 3] + out: [9, 9, 9, 6, 6, 6, 9, 9, 9] + - name: "two_groups" + in: + arr: [8, 8, 9, 9, 8, 9] + out: [5, 4, 4, 3, 7, 5] + - name: "mostly_equal" + in: + arr: [1, 1, 1, 1, 2] + out: [6, 4, 4, 6, 0] + - name: "alternating_four" + in: + arr: [2, 1, 2, 1, 2, 1, 2] + out: [12, 6, 8, 4, 8, 6, 12] + - name: "irregular_three_values" + in: + arr: [3, 4, 3, 5, 4, 3] + out: [7, 3, 5, 0, 3, 8] + - name: "two_repeated_blocks" + in: + arr: [1, 2, 3, 4, 1, 2, 3, 4] + out: [4, 4, 4, 4, 4, 4, 4, 4] + - name: "five_equal" + in: + arr: [10, 10, 10, 10, 10] + out: [10, 7, 6, 7, 10] + - name: "one_value_and_singletons" + in: + arr: [1, 2, 1, 3, 1, 4, 1] + out: [12, 0, 8, 0, 8, 0, 12] + - name: "large_boundary_pair" + in: + arr: [99999, 100000, 99999, 100000] + out: [2, 2, 2, 2] + - name: "repeated_sequence" + in: + arr: [5, 4, 3, 2, 1, 5, 4, 3, 2, 1] + out: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] + - name: "late_repetition" + in: + arr: [1, 1, 2, 3, 2, 3, 2, 3] + out: [1, 1, 6, 6, 4, 4, 6, 6] + - name: "alternating_large_group" + in: + arr: [7, 1, 7, 1, 7, 1, 7, 1] + out: [12, 12, 8, 8, 8, 8, 12, 12] + - name: "two_repeated_ranges" + in: + arr: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] + out: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] + - name: "boundary_mixed" + in: + arr: [100000, 100000, 1, 2, 100000, 100000] + out: [10, 8, 0, 0, 8, 10] + - name: "uneven_repetitions" + in: + arr: [1, 2, 1, 2, 3, 3, 2, 1] + out: [9, 7, 7, 5, 1, 1, 8, 12] + - name: "generated_small_values" + seed: 212101 + in: + arr: + gen: "array" + len: 37 + of: + gen: "int" + min: 1 + max: 6 + distinct: false + sorted: false + - name: "generated_medium_values" + seed: 212102 + in: + arr: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + - name: "stress_dense_duplicates" + seed: 212103 + in: + arr: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 10 + distinct: false + sorted: false + - name: "stress_sparse_values" + seed: 212104 + in: + arr: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + - name: "generated_boundary_values" + seed: 212105 + in: + arr: + gen: "array" + len: 73 + of: + gen: "int" + min: 99995 + max: 100000 + distinct: false + sorted: false diff --git a/tests/2001-2500/2121. intervals-between-identical-elements/sol.py b/tests/2001-2500/2121. intervals-between-identical-elements/sol.py new file mode 100644 index 00000000..59378ab5 --- /dev/null +++ b/tests/2001-2500/2121. intervals-between-identical-elements/sol.py @@ -0,0 +1,18 @@ +class Solution: + def processIndices(self, indices: List[int], ans: List[int]) -> None: + current = sum(indices) + prev = 0 + n = len(indices) + for i in range(n): + current += (indices[i] - prev) * (2 * i - n) + ans[indices[i]] = current + prev = indices[i] + + def getDistances(self, nums: List[int]) -> List[int]: + dict = {} + for i, num in enumerate(nums): + dict.setdefault(num, []).append(i) + ans = [0] * len(nums) + for indices in dict.values(): + self.processIndices(indices, ans) + return ans \ No newline at end of file diff --git a/tests/2001-2500/2122. recover-the-original-array/manifest.yaml b/tests/2001-2500/2122. recover-the-original-array/manifest.yaml new file mode 100644 index 00000000..639bb298 --- /dev/null +++ b/tests/2001-2500/2122. recover-the-original-array/manifest.yaml @@ -0,0 +1,167 @@ +entry: + id: 2122 + title: "recover-the-original-array" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().recoverArray({nums})" + rust: "Solution::recover_array({nums})" + python3: "Solution().recoverArray({nums})" + python2: "Solution().recoverArray({nums})" + ruby: "recover_array({nums})" + java: "new Solution().recoverArray({nums})" + csharp: "new Solution().RecoverArray({nums})" + kotlin: "Solution().recoverArray({nums})" + go: "recoverArray({nums})" + dart: "Solution().recoverArray({nums})" + swift: "Solution().recoverArray({nums})" + typescript: "recoverArray({nums})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().recoverArray(nums, {result})" + checker: | + from collections import Counter + + class Checker: + def recoverArray(self, nums, result): + if not isinstance(result, list) or len(result) * 2 != len(nums): + return False + if any(not isinstance(x, int) or x <= 0 for x in result): + return False + source = Counter(nums) + minimum = min(nums) + candidates = {(value - minimum) // 2 for value in nums + if value > minimum and (value - minimum) % 2 == 0} + for k in candidates: + if k <= 0: + continue + produced = Counter() + for value in result: + if value - k < 1: + break + produced[value - k] += 1 + produced[value + k] += 1 + else: + if produced == source: + return True + return False + +seed: 2122 + +tests: + - name: "example_1" + in: + nums: [2, 10, 6, 4, 8, 12] + - name: "example_2_duplicates" + in: + nums: [1, 1, 3, 3] + - name: "example_3_single_large_gap" + in: + nums: [5, 435] + - name: "single_minimum" + in: + nums: [1, 3] + - name: "single_large_values" + in: + nums: [999999998, 1000000000] + - name: "two_equal_originals" + in: + nums: [4, 4, 10, 10] + - name: "three_equal_originals" + in: + nums: [7, 7, 7, 13, 13, 13] + - name: "duplicate_lower_values" + in: + nums: [3, 3, 3, 23, 23, 23] + - name: "duplicate_cross_values" + in: + nums: [2, 4, 6, 8] + - name: "unsorted_pairs" + in: + nums: [20, 2, 14, 8, 26, 32, 38, 44] + - name: "mixed_small" + in: + nums: [4, 12, 1, 9, 7, 15] + - name: "odd_spacing" + in: + nums: [6, 16, 10, 20, 14, 24, 18, 28] + - name: "large_k" + in: + nums: [1, 100000001, 200000001, 300000001] + - name: "near_integer_limit" + in: + nums: [999999000, 999999100, 999999200, 999999300] + - name: "n_five_duplicates" + in: + nums: [5, 5, 5, 5, 5, 15, 15, 15, 15, 15] + - name: "n_five_varied" + in: + nums: [9, 31, 17, 25, 5, 13, 35, 21, 27, 39] + - name: "repeated_lower_chain" + in: + nums: [2, 2, 2, 6, 6, 6, 10, 10, 10, 14, 14, 14] + - name: "overlapping_candidate_differences" + in: + nums: [2, 6, 8, 12, 14, 18] + - name: "many_same_k" + in: + nums: [4, 8, 6, 10, 8, 12, 10, 14, 12, 16] + - name: "wide_values" + in: + nums: [11, 1011, 111, 1111, 211, 1211, 311, 1311] + - name: "n_ten_regular" + in: + nums: [3, 23, 5, 25, 7, 27, 9, 29, 11, 31, 13, 33, 15, 35, 17, 37, 19, 39, 21, 41] + - name: "n_ten_duplicates" + in: + nums: [1, 1, 1, 1, 1, 9, 9, 9, 9, 9] + - name: "n_ten_permuted" + in: + nums: [52, 2, 92, 42, 12, 102, 22, 72, 32, 112, 62, 82, 102, 52, 72, 22, 32, 62, 12, 82] + - name: "n_twelve_varied" + in: + nums: [4, 34, 9, 39, 14, 44, 19, 49, 24, 54, 29, 59, 7, 37, 12, 42, 17, 47, 22, 52, 27, 57, 32, 62] + - name: "n_twelve_repeated" + in: + nums: [2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24] + - name: "n_fifteen" + in: + nums: [6, 46, 8, 48, 10, 50, 12, 52, 14, 54, 16, 56, 18, 58, 20, 60, 22, 62, 24, 64, 26, 66, 28, 68, 30, 70, 32, 72, 34, 74] + - name: "n_twenty_duplicates" + in: + nums: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25] + - name: "n_twenty_mixed" + in: + nums: [3, 43, 7, 47, 11, 51, 15, 55, 19, 59, 23, 63, 27, 67, 31, 71, 35, 75, 39, 79, 5, 45, 9, 49, 13, 53, 17, 57, 21, 61, 25, 65, 29, 69, 33, 73, 37, 77, 41, 81] + - name: "n_twenty_five" + in: + nums: [101, 151, 102, 152, 103, 153, 104, 154, 105, 155, 106, 156, 107, 157, 108, 158, 109, 159, 110, 160, 111, 161, 112, 162, 113, 163, 114, 164, 115, 165, 116, 166, 117, 167, 118, 168, 119, 169, 120, 170, 121, 171, 122, 172, 123, 173, 124, 174, 125, 175] + - name: "n_thirty_boundary_values" + in: + nums: [1, 101, 2, 102, 3, 103, 4, 104, 5, 105, 6, 106, 7, 107, 8, 108, 9, 109, 10, 110, 11, 111, 12, 112, 13, 113, 14, 114, 15, 115, 16, 116, 17, 117, 18, 118, 19, 119, 20, 120, 21, 121, 22, 122, 23, 123, 24, 124, 25, 125, 26, 126, 27, 127, 28, 128, 29, 129, 30, 130] + - name: "n_thirty_large" + in: + nums: [100000, 1000000, 110000, 1010000, 120000, 1020000, 130000, 1030000, 140000, 1040000, 150000, 1050000, 160000, 1060000, 170000, 1070000, 180000, 1080000, 190000, 1090000, 200000, 1100000, 210000, 1110000, 220000, 1120000, 230000, 1130000, 240000, 1140000] + - name: "n_forty_repeated_pattern" + in: + nums: [2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38, 38, 40, 40] + - name: "n_forty_varied_k" + in: + nums: [6, 86, 10, 90, 14, 94, 18, 98, 22, 102, 26, 106, 30, 110, 34, 114, 38, 118, 42, 122, 46, 126, 50, 130, 54, 134, 58, 138, 62, 142, 66, 146, 70, 150, 74, 154, 78, 158, 82, 162] + - name: "n_fifty_large_stress" + in: + nums: [100000000, 100000100, 100000001, 100000101, 100000002, 100000102, 100000003, 100000103, 100000004, 100000104, 100000005, 100000105, 100000006, 100000106, 100000007, 100000107, 100000008, 100000108, 100000009, 100000109, 100000010, 100000110, 100000011, 100000111, 100000012, 100000112, 100000013, 100000113, 100000014, 100000114, 100000015, 100000115, 100000016, 100000116, 100000017, 100000117, 100000018, 100000118, 100000019, 100000119, 100000020, 100000120, 100000021, 100000121, 100000022, 100000122, 100000023, 100000123, 100000024, 100000124] + - name: "n_hundred_duplicate_stress" + in: + nums: [1, 3] diff --git a/tests/2001-2500/2122. recover-the-original-array/sol.py b/tests/2001-2500/2122. recover-the-original-array/sol.py new file mode 100644 index 00000000..f6afddaa --- /dev/null +++ b/tests/2001-2500/2122. recover-the-original-array/sol.py @@ -0,0 +1,15 @@ +class Solution: + def recoverArray(self, nums: List[int]) -> List[int]: + nums.sort() + cnt = Counter(nums) + for i in range(1, len(nums)): + diff = nums[i] - nums[0] + if diff and diff&1 == 0: + ans = [] + freq = cnt.copy() + for k, v in freq.items(): + if v: + if freq[k+diff] < v: break + ans.extend([k+diff//2]*v) + freq[k+diff] -= v + else: return ans \ No newline at end of file diff --git a/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/manifest.yaml b/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/manifest.yaml new file mode 100644 index 00000000..2636eebb --- /dev/null +++ b/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/manifest.yaml @@ -0,0 +1,214 @@ +entry: + id: 2124 + title: "check-if-all-as-appears-before-all-bs" + params: + s: + type: string + call: + cpp: "Solution().checkString({s})" + rust: "Solution::check_string({s})" + python3: "Solution().checkString({s})" + python2: "Solution().checkString({s})" + ruby: "check_string({s})" + java: "new Solution().checkString({s})" + csharp: "new Solution().CheckString({s})" + kotlin: "Solution().checkString({s})" + go: "checkString({s})" + dart: "Solution().checkString({s})" + swift: "Solution().checkString({s})" + typescript: "checkString({s})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().checkString(s, {result})" + checker: | + class Checker: + def checkString(self, s, result): + return isinstance(result, bool) and result == ("ba" not in s) + +seed: 2124 + +tests: + - name: "ex1_all_a_then_b" + in: + s: "aaabbb" + out: true + - name: "ex2_alternating" + in: + s: "abab" + out: false + - name: "ex3_all_b" + in: + s: "bbb" + out: true + - name: "single_a" + in: + s: "a" + out: true + - name: "single_b" + in: + s: "b" + out: true + - name: "one_a_one_b_ordered" + in: + s: "ab" + out: true + - name: "one_b_one_a_inverted" + in: + s: "ba" + out: false + - name: "all_a_length_10" + in: + s: "aaaaaaaaaa" + out: true + - name: "all_b_length_10" + in: + s: "bbbbbbbbbb" + out: true + - name: "one_b_before_many_a" + in: + s: "baaaa" + out: false + - name: "many_a_before_one_b" + in: + s: "aaaab" + out: true + - name: "one_a_after_many_b" + in: + s: "bbba" + out: false + - name: "single_inversion_middle" + in: + s: "aababb" + out: false + - name: "inversion_near_end" + in: + s: "aaabbba" + out: false + - name: "inversion_near_start" + in: + s: "baaabbb" + out: false + - name: "two_runs_ordered" + in: + s: "aaaaabbbbb" + out: true + - name: "two_runs_reversed" + in: + s: "bbbbbaaaaa" + out: false + - name: "aab" + in: + s: "aab" + out: true + - name: "abb" + in: + s: "abb" + out: true + - name: "baa" + in: + s: "baa" + out: false + - name: "bba" + in: + s: "bba" + out: false + - name: "aabbaabb" + in: + s: "aabbaabb" + out: false + - name: "abbbbb" + in: + s: "abbbbb" + out: true + - name: "aaaaab" + in: + s: "aaaaab" + out: true + - name: "ababab" + in: + s: "ababab" + out: false + - name: "bababa" + in: + s: "bababa" + out: false + - name: "alternating_start_a" + in: + s: "ababababab" + out: false + - name: "alternating_start_b" + in: + s: "bababababa" + out: false + - name: "late_a_single" + in: + s: "aaaaaaaaab" + out: true + - name: "late_b_single" + in: + s: "abbbbbbbbb" + out: true + - name: "max_ordered" + in: + s: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + out: true + - name: "max_all_a" + in: + s: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + out: true + - name: "max_inversion_at_end" + in: + s: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba" + out: false + - name: "generated_short" + seed: 101 + in: + s: + gen: "str" + len: + gen: "int" + min: 1 + max: 20 + alphabet: "ab" + - name: "generated_medium" + seed: 202 + in: + s: + gen: "str" + len: + gen: "int" + min: 21 + max: 60 + alphabet: "ab" + - name: "generated_maximum" + seed: 303 + in: + s: + gen: "str" + len: 100 + alphabet: "ab" + - name: "generated_maximum_second" + seed: 404 + in: + s: + gen: "str" + len: 100 + alphabet: "ab" + - name: "generated_boundary_length" + seed: 505 + in: + s: + gen: "str" + len: + gen: "int" + min: 99 + max: 100 + alphabet: "ab" diff --git a/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/sol.py b/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/sol.py new file mode 100644 index 00000000..ef51c3a7 --- /dev/null +++ b/tests/2001-2500/2124. check-if-all-as-appears-before-all-bs/sol.py @@ -0,0 +1,6 @@ +class Solution: + def checkString(self, s: str) -> bool: + if 'ba'in s: + return False + + return True \ No newline at end of file diff --git a/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/manifest.yaml b/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/manifest.yaml new file mode 100644 index 00000000..79673f33 --- /dev/null +++ b/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/manifest.yaml @@ -0,0 +1,195 @@ +entry: + id: 2125 + title: "number-of-laser-beams-in-a-bank" + params: + bank: + type: array + items: + type: string + call: + cpp: "Solution().numberOfBeams({bank})" + rust: "Solution::number_of_beams({bank})" + python3: "Solution().numberOfBeams({bank})" + python2: "Solution().numberOfBeams({bank})" + ruby: "number_of_beams({bank})" + java: "new Solution().numberOfBeams({bank})" + csharp: "new Solution().NumberOfBeams({bank})" + kotlin: "Solution().numberOfBeams({bank})" + go: "numberOfBeams({bank})" + dart: "Solution().numberOfBeams({bank})" + swift: "Solution().numberOfBeams({bank})" + typescript: "numberOfBeams({bank})" + +judge: + type: "exact" + +limits: + time_ms: 2000 + memory_mb: 256 + +oracle: + python3: + call: "Checker().numberOfBeams(bank, result)" + checker: | + class Checker: + def numberOfBeams(self, bank, result): + previous = 0 + expected = 0 + for row in bank: + devices = row.count("1") + if devices: + expected += previous * devices + previous = devices + return result == expected + +seed: 2125 + +tests: + - name: "example_one" + in: + bank: ["011001", "000000", "010100", "001000"] + out: 8 + - name: "example_two" + in: + bank: ["000", "111", "000"] + out: 0 + - name: "single_empty_row" + in: + bank: ["0"] + out: 0 + - name: "single_device_row" + in: + bank: ["1"] + out: 0 + - name: "two_adjacent_singletons" + in: + bank: ["1", "1"] + out: 1 + - name: "two_adjacent_counts" + in: + bank: ["1101", "0110"] + out: 6 + - name: "zero_rows_between" + in: + bank: ["1000", "0000", "0000", "0010"] + out: 1 + - name: "zero_rows_do_not_reset" + in: + bank: ["101", "000", "010", "000", "111"] + out: 5 + - name: "three_active_rows" + in: + bank: ["11", "10", "01"] + out: 3 + - name: "leading_empty_rows" + in: + bank: ["000", "000", "101", "000", "011"] + out: 4 + - name: "trailing_empty_rows" + in: + bank: ["101", "000", "011", "000", "000"] + out: 4 + - name: "all_empty" + in: + bank: ["0000", "0000", "0000", "0000"] + out: 0 + - name: "one_active_among_empty" + in: + bank: ["000", "000", "010", "000"] + out: 0 + - name: "all_ones_two_rows" + in: + bank: ["11111", "11111"] + out: 25 + - name: "all_ones_three_rows" + in: + bank: ["111", "111", "111"] + out: 18 + - name: "alternating_rows" + in: + bank: ["10101", "01010", "10101", "01010"] + out: 18 + - name: "alternating_with_gaps" + in: + bank: ["1010", "0000", "0101", "0000", "1010"] + out: 8 + - name: "many_zero_rows" + in: + bank: ["100", "000", "000", "000", "001", "000", "000", "010"] + out: 2 + - name: "dense_then_sparse" + in: + bank: ["111111", "000000", "000001"] + out: 6 + - name: "sparse_then_dense" + in: + bank: ["100000", "000000", "111111"] + out: 6 + - name: "middle_active_breaks_beam" + in: + bank: ["111", "000", "100", "000", "011"] + out: 5 + - name: "consecutive_active_breaks_skip" + in: + bank: ["10", "01", "11"] + out: 3 + - name: "single_column_pattern" + in: + bank: ["1", "0", "1", "1", "0", "1"] + out: 3 + - name: "single_column_sparse" + in: + bank: ["0", "1", "0", "0", "1", "0", "1"] + out: 2 + - name: "row_counts_1_2_3" + in: + bank: ["1000", "1100", "1110"] + out: 8 + - name: "row_counts_3_1_2" + in: + bank: ["1110", "0000", "1000", "0011"] + out: 5 + - name: "repeated_counts" + in: + bank: ["1010", "0000", "1010", "0000", "1010"] + out: 8 + - name: "late_first_active" + in: + bank: ["00000", "00000", "00100", "00000", "11111"] + out: 5 + - name: "early_last_active" + in: + bank: ["11111", "00000", "00100", "00000", "00000"] + out: 5 + - name: "max_width_single_pair" + in: + bank: ["1111111111", "0000000000", "0000000001"] + out: 10 + - name: "max_width_dense_pair" + in: + bank: ["1111111111", "1111111111"] + out: 100 + - name: "mixed_width_five_rows" + in: + bank: ["00101", "00000", "11111", "00010", "10000"] + out: 16 + - name: "alternating_single_devices" + in: + bank: ["10000", "00000", "00010", "00000", "00001", "00000"] + out: 2 + - name: "four_active_count_product" + in: + bank: ["10101", "00000", "11111", "00000", "11000", "00000", "00100"] + out: 27 + - name: "all_rows_one_device" + in: + bank: ["100000", "010000", "001000", "000100", "000010", "000001"] + out: 5 + - name: "large_width_generated_a" + in: + bank: ["11111111111111111111", "00000000000000000000", "10101010101010101010", "00000000000000000000", "11111111110000000000"] + out: 300 + - name: "large_width_generated_b" + in: + bank: ["10000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000", "11111111111111111111111111111111111111111111111111", "01000000000000000000000000000000000000000000000000"] + out: 100 diff --git a/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/sol.py b/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/sol.py new file mode 100644 index 00000000..5d3bc125 --- /dev/null +++ b/tests/2001-2500/2125. number-of-laser-beams-in-a-bank/sol.py @@ -0,0 +1,10 @@ +class Solution: + def numberOfBeams(self, bank: List[str]) -> int: + ans=0 + prev=0 + for row in bank: + dev=row.count('1') + if dev>0: + ans+=dev*prev + prev=dev + return ans \ No newline at end of file diff --git a/tests/2001-2500/2126. destroying-asteroids/manifest.yaml b/tests/2001-2500/2126. destroying-asteroids/manifest.yaml new file mode 100644 index 00000000..57b4d976 --- /dev/null +++ b/tests/2001-2500/2126. destroying-asteroids/manifest.yaml @@ -0,0 +1,273 @@ +entry: + id: 2126 + title: "destroying-asteroids" + params: + mass: + type: int + asteroids: + type: array + items: + type: int + call: + cpp: "Solution().asteroidsDestroyed({mass}, {asteroids})" + rust: "Solution::asteroids_destroyed({mass}, {asteroids})" + python3: "Solution().asteroidsDestroyed({mass}, {asteroids})" + python2: "Solution().asteroidsDestroyed({mass}, {asteroids})" + ruby: "asteroids_destroyed({mass}, {asteroids})" + java: "new Solution().asteroidsDestroyed({mass}, {asteroids})" + csharp: "new Solution().AsteroidsDestroyed({mass}, {asteroids})" + kotlin: "Solution().asteroidsDestroyed({mass}, {asteroids})" + go: "asteroidsDestroyed({mass}, {asteroids})" + dart: "Solution().asteroidsDestroyed({mass}, {asteroids})" + swift: "Solution().asteroidsDestroyed({mass}, {asteroids})" + typescript: "asteroidsDestroyed({mass}, {asteroids})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 256 +oracle: + python3: + call: "Checker().asteroidsDestroyed(mass, asteroids, {result})" + checker: | + class Checker: + def asteroidsDestroyed(self, mass, asteroids, result): + if not isinstance(result, bool): + return False + current = mass + for asteroid in sorted(asteroids): + if asteroid > current: + return result is False + current += asteroid + return result is True +seed: 2126 +tests: + - name: "example-one" + in: + mass: 10 + asteroids: [3, 9, 19, 5, 21] + out: true + - name: "example-two" + in: + mass: 5 + asteroids: [4, 9, 23, 4] + out: false + - name: "single-equal" + in: + mass: 1 + asteroids: [1] + out: true + - name: "single-too-large" + in: + mass: 1 + asteroids: [2] + out: false + - name: "unordered-chain" + in: + mass: 3 + asteroids: [10, 1, 2, 4] + out: true + - name: "blocked-after-small" + in: + mass: 2 + asteroids: [1, 10] + out: false + - name: "all-equal" + in: + mass: 5 + asteroids: [5, 5, 5, 5] + out: true + - name: "all-one" + in: + mass: 1 + asteroids: [1, 1, 1, 1, 1] + out: true + - name: "needs-sort" + in: + mass: 1 + asteroids: [100, 1, 2, 4, 8, 16, 32] + out: false + - name: "powers-success" + in: + mass: 1 + asteroids: [1, 2, 4, 8, 16, 32] + out: true + - name: "exact-after-growth" + in: + mass: 4 + asteroids: [8, 4] + out: true + - name: "just-insufficient" + in: + mass: 4 + asteroids: [5] + out: false + - name: "large-initial-mass" + in: + mass: 100000 + asteroids: [100000, 99999, 1] + out: true + - name: "largest-first-input" + in: + mass: 6 + asteroids: [20, 7, 6, 1] + out: true + - name: "cannot-reach-largest" + in: + mass: 6 + asteroids: [20, 7, 6] + out: false + - name: "duplicates-enable" + in: + mass: 3 + asteroids: [6, 3, 3] + out: true + - name: "duplicates-insufficient" + in: + mass: 3 + asteroids: [7, 3] + out: false + - name: "many-small-before-large" + in: + mass: 1 + asteroids: [50, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: false + - name: "twenty-ones" + in: + mass: 1 + asteroids: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: true + - name: "boundary-accumulation" + in: + mass: 10 + asteroids: [11, 1] + out: true + - name: "generated-small" + seed: 1 + in: + mass: + gen: "int" + min: 1 + max: 100 + asteroids: + gen: "array" + len: 30 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + elemType: "int" + - name: "generated-medium" + seed: 2 + in: + mass: + gen: "int" + min: 1 + max: 100000 + asteroids: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-large" + seed: 3 + in: + mass: + gen: "int" + min: 1 + max: 100000 + asteroids: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-large-small-values" + seed: 4 + in: + mass: 1 + asteroids: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 10 + distinct: false + sorted: false + elemType: "int" + - name: "generated-large-max-values" + seed: 5 + in: + mass: 100000 + asteroids: + gen: "array" + len: 100000 + of: + gen: "int" + min: 90000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "late-failure" + in: + mass: 5 + asteroids: [1, 2, 4, 100] + out: false + - name: "late-success" + in: + mass: 5 + asteroids: [1, 2, 4, 12] + out: true + - name: "same-as-planet" + in: + mass: 99999 + asteroids: [99999] + out: true + - name: "max-asteroid-with-growth" + in: + mass: 50000 + asteroids: [50000, 100000] + out: true + - name: "max-asteroid-without-growth" + in: + mass: 99999 + asteroids: [100000] + out: false + - name: "smallest-mass-progress" + in: + mass: 1 + asteroids: [3, 1, 1] + out: true + - name: "smallest-mass-fails" + in: + mass: 1 + asteroids: [4, 1, 1] + out: false + - name: "permuted-complete" + in: + mass: 2 + asteroids: [9, 2, 1, 4] + out: true + - name: "permuted-incomplete" + in: + mass: 2 + asteroids: [10, 2, 1, 4] + out: false + - name: "ten-equal-large" + in: + mass: 10000 + asteroids: [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000] + out: true diff --git a/tests/2001-2500/2126. destroying-asteroids/sol.py b/tests/2001-2500/2126. destroying-asteroids/sol.py new file mode 100644 index 00000000..bd3f83a3 --- /dev/null +++ b/tests/2001-2500/2126. destroying-asteroids/sol.py @@ -0,0 +1,14 @@ +class Solution: + def asteroidsDestroyed(self, mass: int, asteroids: List[int]) -> bool: + xmax=max(asteroids) + freq=[0]*(1+xmax) + for x in asteroids: + freq[x]+=1 + planet=mass + for x, f in enumerate(freq): + if f==0: + continue + if x>planet: + return False + planet+=x*f + return True \ No newline at end of file diff --git a/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/manifest.yaml b/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/manifest.yaml new file mode 100644 index 00000000..e0933cb3 --- /dev/null +++ b/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/manifest.yaml @@ -0,0 +1,223 @@ +entry: + id: 2127 + title: "maximum-employees-to-be-invited-to-a-meeting" + params: + favorite: + type: array + items: + type: int + call: + cpp: "Solution().maximumInvitations({favorite})" + rust: "Solution::maximum_invitations({favorite})" + python3: "Solution().maximumInvitations({favorite})" + python2: "Solution().maximumInvitations({favorite})" + ruby: "maximum_invitations({favorite})" + java: "new Solution().maximumInvitations({favorite})" + csharp: "new Solution().MaximumInvitations({favorite})" + kotlin: "Solution().maximumInvitations({favorite})" + go: "maximumInvitations({favorite})" + dart: "Solution().maximumInvitations({favorite})" + swift: "Solution().maximumInvitations({favorite})" + typescript: "maximumInvitations({favorite})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maximumInvitations(favorite, {result})" + checker: | + class Checker: + def maximumInvitations(self, favorite, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(favorite) + indeg = [0] * n + depth = [0] * n + for v in favorite: + if not isinstance(v, int) or v < 0 or v >= n: + return False + indeg[v] += 1 + q = [i for i, d in enumerate(indeg) if d == 0] + head = 0 + while head < len(q): + u = q[head] + head += 1 + v = favorite[u] + depth[v] = max(depth[v], depth[u] + 1) + indeg[v] -= 1 + if indeg[v] == 0: + q.append(v) + best_cycle = 0 + pairs = 0 + seen = [False] * n + for i in range(n): + if indeg[i] == 0 or seen[i]: + continue + cur = i + size = 0 + while not seen[cur]: + seen[cur] = True + cur = favorite[cur] + size += 1 + if size == 2: + pairs += 2 + depth[i] + depth[favorite[i]] + else: + best_cycle = max(best_cycle, size) + return result == max(best_cycle, pairs) + +seed: 2127 + +tests: + - name: "example_1" + in: + favorite: [2, 2, 1, 2] + out: 3 + - name: "example_2_cycle_three" + in: + favorite: [1, 2, 0] + out: 3 + - name: "example_3" + in: + favorite: [3, 0, 1, 4, 1] + out: 4 + - name: "single_mutual_pair" + in: + favorite: [1, 0, 0] + out: 3 + - name: "pair_with_chain" + in: + favorite: [1, 0, 0, 2, 3] + out: 5 + - name: "pair_two_chains" + in: + favorite: [1, 0, 0, 1, 3, 4] + out: 6 + - name: "cycle_four" + in: + favorite: [1, 2, 3, 0, 0] + out: 4 + - name: "cycle_five" + in: + favorite: [1, 2, 3, 4, 0, 1] + out: 5 + - name: "cycle_two_beats_cycle_three" + in: + favorite: [1, 0, 3, 4, 2] + out: 3 + - name: "cycle_three_beats_pair_chains" + in: + favorite: [1, 2, 0, 4, 3, 3] + out: 3 + - name: "two_disconnected_pairs" + in: + favorite: [1, 0, 3, 2, 5, 4] + out: 6 + - name: "pair_and_cycle_three" + in: + favorite: [1, 0, 3, 4, 2] + out: 3 + - name: "long_chain_into_pair" + in: + favorite: [1, 0, 0, 2, 3, 4, 5] + out: 7 + - name: "branching_chain_into_pair" + in: + favorite: [1, 0, 0, 0, 3, 4] + out: 5 + - name: "branching_selects_longest" + in: + favorite: [1, 0, 0, 0, 3, 4, 5] + out: 6 + - name: "all_to_one_cycle" + in: + favorite: [1, 0, 0, 0, 0, 0, 0, 0] + out: 3 + - name: "many_pairs_sum" + in: + favorite: [1, 0, 3, 2, 5, 4, 7, 6] + out: 8 + - name: "pair_chain_and_long_cycle" + in: + favorite: [1, 0, 0, 4, 5, 6, 3] + out: 4 + - name: "cycle_with_incoming_tail" + in: + favorite: [1, 2, 0, 0, 3, 4] + out: 3 + - name: "nested_tail_branch" + in: + favorite: [1, 0, 0, 2, 2, 4, 5, 6] + out: 7 + - name: "three_cycle_and_pair" + in: + favorite: [1, 2, 0, 4, 3] + out: 3 + - name: "four_cycle_and_pair" + in: + favorite: [1, 2, 3, 0, 5, 4] + out: 4 + - name: "several_short_tails" + in: + favorite: [1, 0, 0, 0, 0, 1, 5, 6] + out: 6 + - name: "cycle_six" + in: + favorite: [1, 2, 3, 4, 5, 0, 0] + out: 6 + - name: "cycle_seven" + in: + favorite: [1, 2, 3, 4, 5, 6, 0, 1] + out: 7 + - name: "pair_with_competing_depths" + in: + favorite: [1, 0, 0, 2, 3, 0, 5, 6, 7] + out: 6 + - name: "cycle_three_with_tail" + in: + favorite: [1, 2, 0, 1, 3, 4] + out: 3 + - name: "cycle_four_with_tail" + in: + favorite: [1, 2, 3, 0, 1, 4] + out: 4 + - name: "two_pairs_with_tails" + in: + favorite: [1, 0, 0, 2, 5, 4, 4, 6] + out: 8 + - name: "large_cycle" + in: + favorite: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] + out: 10 + - name: "large_pair_chain" + in: + favorite: [1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: 12 + - name: "large_many_pairs" + in: + favorite: [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14] + out: 16 + - name: "large_disconnected_cycles" + in: + favorite: [1, 2, 0, 4, 5, 3, 7, 8, 6, 10, 11, 9] + out: 3 + + - name: "minimum_length_three" + in: + favorite: [1, 0, 1] + out: 3 + - name: "maximum_n_cycle" + in: + favorite: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 99999 + distinct: false + sorted: false diff --git a/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/sol.py b/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/sol.py new file mode 100644 index 00000000..25c194a5 --- /dev/null +++ b/tests/2001-2500/2127. maximum-employees-to-be-invited-to-a-meeting/sol.py @@ -0,0 +1,48 @@ +from collections import deque + +class Solution(object): + def maximumInvitations(self, favorite): + n = len(favorite) + in_deg = [0] * n + chain_len = [0] * n + visited = [False] * n + q = deque() + + # Count how many people favor each employee + for f in favorite: + in_deg[f] += 1 + + # Start with employees no one favorites (chain starters) + for i in range(n): + if in_deg[i] == 0: + q.append(i) + + # Process chains to calculate max chain lengths + while q: + u = q.popleft() + visited[u] = True + v = favorite[u] + chain_len[v] = max(chain_len[v], chain_len[u] + 1) + in_deg[v] -= 1 + if in_deg[v] == 0: + q.append(v) + + max_cycle, pair_chains = 0, 0 + + # Detect cycles and calculate results + for i in range(n): + if visited[i]: + continue + cycle_len = 0 + current = i + # Measure cycle length + while not visited[current]: + visited[current] = True + current = favorite[current] + cycle_len += 1 + if cycle_len == 2: # Mutual pair + pair_chains += 2 + chain_len[i] + chain_len[favorite[i]] + else: + max_cycle = max(max_cycle, cycle_len) + + return max(max_cycle, pair_chains) \ No newline at end of file diff --git a/tests/2001-2500/2129. capitalize-the-title/manifest.yaml b/tests/2001-2500/2129. capitalize-the-title/manifest.yaml new file mode 100644 index 00000000..8d0979db --- /dev/null +++ b/tests/2001-2500/2129. capitalize-the-title/manifest.yaml @@ -0,0 +1,189 @@ +entry: + id: 2129 + title: "capitalize-the-title" + params: + title: + type: string + call: + cpp: "Solution().capitalizeTitle({title})" + rust: "Solution::capitalize_title({title})" + python3: "Solution().capitalizeTitle({title})" + python2: "Solution().capitalizeTitle({title})" + ruby: "capitalize_title({title})" + java: "new Solution().capitalizeTitle({title})" + csharp: "new Solution().CapitalizeTitle({title})" + kotlin: "Solution().capitalizeTitle({title})" + go: "capitalizeTitle({title})" + dart: "Solution().capitalizeTitle({title})" + swift: "Solution().capitalizeTitle({title})" + typescript: "capitalizeTitle({title})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 128 +oracle: + python3: + call: "Checker().capitalizeTitle(title, {result})" + checker: | + class Checker: + def capitalizeTitle(self, title, result): + expected = ' '.join(w.lower() if len(w) <= 2 else w[0].upper() + w[1:].lower() for w in title.split(' ')) + return isinstance(result, str) and result == expected +seed: 2129 +tests: + - name: "example-one" + in: + title: "capiTalIze tHe titLe" + out: "Capitalize The Title" + - name: "example-two" + in: + title: "First leTTeR of EACH Word" + out: "First Letter of Each Word" + - name: "example-three" + in: + title: "i lOve leetcode" + out: "i Love Leetcode" + - name: "one-lower" + in: + title: "A" + out: "a" + - name: "two-upper" + in: + title: "AB" + out: "ab" + - name: "three-upper" + in: + title: "ABC" + out: "Abc" + - name: "four-mixed" + in: + title: "aBcD" + out: "Abcd" + - name: "two-short-words" + in: + title: "I AM" + out: "i am" + - name: "length-boundaries" + in: + title: "A AB ABC ABCD" + out: "a ab Abc Abcd" + - name: "already-correct" + in: + title: "Hello World" + out: "Hello World" + - name: "all-lower" + in: + title: "hello there general kenobi" + out: "Hello There General Kenobi" + - name: "all-upper" + in: + title: "HELLO TO THE WORLD" + out: "Hello to The World" + - name: "many-short" + in: + title: "A b CD ef" + out: "a b cd ef" + - name: "mixed-case-words" + in: + title: "mIXed CaSE WoRDS" + out: "Mixed Case Words" + - name: "single-long" + in: + title: "lEeTcOdE" + out: "Leetcode" + - name: "two-word-boundary" + in: + title: "TO be" + out: "to be" + - name: "three-letter-repeat" + in: + title: "aBc DeF gHi" + out: "Abc Def Ghi" + - name: "single-letter-series" + in: + title: "A B C D E" + out: "a b c d e" + - name: "long-word-with-short" + in: + title: "OPENAI is GREAT" + out: "Openai is Great" + - name: "near-limit" + in: + title: "aBcDeFgHiJkLmNoPqRsTuVwXyZ" + out: "Abcdefghijklmnopqrstuvwxyz" + - name: "generated-min" + seed: 1 + in: + title: + gen: "str" + len: 1 + alphabet: "aA" + - name: "generated-two" + seed: 2 + in: + title: + gen: "str" + len: 2 + alphabet: "aAbB" + - name: "generated-three" + seed: 3 + in: + title: + gen: "str" + len: 3 + alphabet: "aAbB" + - name: "generated-long" + seed: 4 + in: + title: + gen: "str" + len: 100 + alphabet: "aAbBcC" + - name: "generated-medium" + seed: 5 + in: + title: + gen: "str" + len: 50 + alphabet: "xXyY" + - name: "first-only-capital" + in: + title: "hELLO" + out: "Hello" + - name: "lowercase-short" + in: + title: "aB cD" + out: "ab cd" + - name: "four-words" + in: + title: "ONE two THree fOUR" + out: "One Two Three Four" + - name: "alternating" + in: + title: "aBcDeF GhI jK" + out: "Abcdef Ghi jk" + - name: "small-and-large" + in: + title: "ON a RoCkEt" + out: "on a Rocket" + - name: "five-letter" + in: + title: "pYtHoN" + out: "Python" + - name: "short-before-long" + in: + title: "an EXAMPLE" + out: "an Example" + - name: "long-before-short" + in: + title: "EXAMPLE OF" + out: "Example of" + - name: "sentence-variety" + in: + title: "ThE quick BROWN fox" + out: "The Quick Brown Fox" + - name: "maximum-word-mix" + in: + title: "aB CdE fGhI jK" + out: "ab Cde Fghi jk" diff --git a/tests/2001-2500/2129. capitalize-the-title/sol.py b/tests/2001-2500/2129. capitalize-the-title/sol.py new file mode 100644 index 00000000..402040c2 --- /dev/null +++ b/tests/2001-2500/2129. capitalize-the-title/sol.py @@ -0,0 +1,12 @@ +class Solution: + def capitalizeTitle(self, title): + words = title.split() + for i in range(len(words)): + word_len = len(words[i]) + + if word_len <= 2: + words[i] = words[i].lower() + else: + words[i] = words[i].capitalize() + + return " ".join(words) \ No newline at end of file diff --git a/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/manifest.yaml b/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/manifest.yaml new file mode 100644 index 00000000..b39dc78a --- /dev/null +++ b/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/manifest.yaml @@ -0,0 +1,214 @@ +entry: + id: 2130 + title: "maximum-twin-sum-of-a-linked-list" + params: + head: + type: list_node + call: + cpp: "Solution().pairSum({head})" + rust: "Solution::pair_sum({head})" + python3: "Solution().pairSum({head})" + python2: "Solution().pairSum({head})" + ruby: "pair_sum({head})" + java: "new Solution().pairSum({head})" + csharp: "new Solution().PairSum({head})" + kotlin: "Solution().pairSum({head})" + go: "pairSum({head})" + dart: "Solution().pairSum({head})" + swift: "Solution().pairSum({head})" + typescript: "pairSum({head})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().pairSum(head, {result})" + checker: | + class Checker: + def pairSum(self, head, result): + if not isinstance(head, list) or len(head) < 2 or len(head) % 2: + return False + if any(not isinstance(value, int) or isinstance(value, bool) or value < 1 or value > 100000 for value in head): + return False + if not isinstance(result, int) or isinstance(result, bool): + return False + return result == max(head[i] + head[-1 - i] for i in range(len(head) // 2)) + +seed: 2130 + +tests: + - name: "example_1" + in: + head: [5, 4, 2, 1] + out: 6 + - name: "example_2" + in: + head: [4, 2, 2, 3] + out: 7 + - name: "example_3" + in: + head: [1, 100000] + out: 100001 + - name: "minimum_equal" + in: + head: [1, 1] + out: 2 + - name: "minimum_extremes" + in: + head: [1, 100000] + out: 100001 + - name: "four_increasing" + in: + head: [1, 2, 3, 4] + out: 5 + - name: "four_decreasing" + in: + head: [9, 7, 5, 3] + out: 12 + - name: "maximum_all" + in: + head: [100000, 100000, 100000, 100000] + out: 200000 + - name: "alternating_extremes" + in: + head: [1, 100000, 1, 100000, 1, 100000] + out: 100001 + - name: "center_pair_max" + in: + head: [1, 1, 100000, 100000] + out: 100001 + - name: "outer_pair_max" + in: + head: [100000, 2, 3, 1] + out: 100001 + - name: "duplicate_values" + in: + head: [8, 8, 8, 8, 8, 8, 8, 8] + out: 16 + - name: "six_mixed" + in: + head: [10, 20, 30, 40, 50, 60] + out: 70 + - name: "six_middle_peak" + in: + head: [1, 2, 100, 100, 2, 1] + out: 200 + - name: "six_outer_peak" + in: + head: [100, 2, 3, 4, 5, 1] + out: 101 + - name: "eight_balanced" + in: + head: [11, 22, 33, 44, 55, 66, 77, 88] + out: 99 + - name: "eight_peak_third" + in: + head: [1, 1, 100000, 1, 1, 1, 1, 1] + out: 100001 + - name: "ten_constant" + in: + head: [42, 42, 42, 42, 42, 42, 42, 42, 42, 42] + out: 84 + - name: "ten_varied" + in: + head: [3, 14, 15, 92, 65, 35, 89, 79, 32, 38] + out: 181 + - name: "twelve_extreme_inner" + in: + head: [1, 2, 3, 4, 100000, 6, 6, 100000, 4, 3, 2, 1] + out: 200000 + - name: "twelve_extreme_outer" + in: + head: [100000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + out: 100001 + - name: "sixteen_small" + in: + head: [1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1] + out: 16 + - name: "sixteen_unbalanced" + in: + head: [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + out: 115 + - name: "large_values_pairing" + in: + head: [99999, 99998, 99997, 99996, 2, 3, 4, 5] + out: 100004 + - name: "large_values_even" + in: + head: [99999, 1, 99998, 2, 99997, 3, 99996, 4] + out: 100003 + - name: "twenty_four_pattern" + in: + head: [1, 100, 2, 99, 3, 98, 4, 97, 97, 4, 98, 3, 99, 2, 100, 1] + out: 200 + - name: "twenty_four_peak" + in: + head: [1, 1, 1, 1, 1, 100000, 100000, 1, 1, 1, 1, 1] + out: 200000 + - name: "thirty_two_constant" + in: + head: [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7] + out: 14 + - name: "thirty_two_edge_mix" + in: + head: [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993] + out: 100008 + - name: "forty_sparse_values" + in: + head: [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991, 11, 99990, 12, 99989, 13, 99988, 14, 99987, 15, 99986, 16, 99985, 17, 99984, 18, 99983, 19, 99982, 20, 99981, 21, 99980, 22, 99979] + out: 100022 + - name: "generated_small" + in: + head: + gen: "array" + len: 40 + of: + gen: "int" + min: 1 + max: 100000 + seed: 101 + - name: "generated_medium" + in: + head: + gen: "array" + len: 1000 + of: + gen: "int" + min: 1 + max: 100000 + seed: 102 + - name: "generated_duplicates" + in: + head: + gen: "array" + len: 200 + of: + gen: "int" + min: 1 + max: 3 + seed: 103 + - name: "stress_50000" + in: + head: + gen: "array" + len: 50000 + of: + gen: "int" + min: 1 + max: 100000 + seed: 104 + - name: "stress_100000" + in: + head: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 100000 + seed: 105 diff --git a/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/sol.py b/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/sol.py new file mode 100644 index 00000000..a29360f7 --- /dev/null +++ b/tests/2001-2500/2130. maximum-twin-sum-of-a-linked-list/sol.py @@ -0,0 +1,8 @@ +class Solution: + def pairSum(self, head: Optional[ListNode]) -> int: + values = [] + node = head + while node: + values.append(node.val) + node = node.next + return max(values[i] + values[-1 - i] for i in range(len(values) // 2)) diff --git a/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/manifest.yaml b/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/manifest.yaml new file mode 100644 index 00000000..cf0351a1 --- /dev/null +++ b/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/manifest.yaml @@ -0,0 +1,247 @@ +entry: + id: 2131 + title: "longest-palindrome-by-concatenating-two-letter-words" + params: + words: + type: array + items: + type: string + call: + cpp: "Solution().longestPalindrome({words})" + rust: "Solution::longest_palindrome({words})" + python3: "Solution().longestPalindrome({words})" + python2: "Solution().longestPalindrome({words})" + ruby: "longest_palindrome({words})" + java: "new Solution().longestPalindrome({words})" + csharp: "new Solution().LongestPalindrome({words})" + kotlin: "Solution().longestPalindrome({words})" + go: "longestPalindrome({words})" + dart: "Solution().longestPalindrome({words})" + swift: "Solution().longestPalindrome({words})" + typescript: "longestPalindrome({words})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().longestPalindrome(words, {result})" + checker: | + class Checker: + def longestPalindrome(self, words, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + counts = {} + for word in words: + if not isinstance(word, str) or len(word) != 2: + return False + counts[word] = counts.get(word, 0) + 1 + total = 0 + middle = False + for word, count in counts.items(): + reverse = word[::-1] + if word == reverse: + total += (count // 2) * 4 + middle = middle or (count % 2 == 1) + elif word < reverse: + total += min(count, counts.get(reverse, 0)) * 4 + if middle: + total += 2 + return result == total + +seed: 2131 + +tests: + - name: "example_1" + in: + words: ["lc", "cl", "gg"] + out: 6 + - name: "example_2" + in: + words: ["ab", "ty", "yt", "lc", "cl", "ab"] + out: 8 + - name: "example_3" + in: + words: ["cc", "ll", "xx"] + out: 2 + - name: "single_nonpalindrome" + in: + words: ["ab"] + out: 0 + - name: "single_palindrome" + in: + words: ["aa"] + out: 2 + - name: "one_matching_pair" + in: + words: ["ab", "ba"] + out: 4 + - name: "unmatched_reverse" + in: + words: ["ab", "ab", "ba"] + out: 4 + - name: "three_same_nonpalindromes" + in: + words: ["ab", "ab", "ab"] + out: 0 + - name: "four_same_nonpalindromes" + in: + words: ["ab", "ab", "ab", "ab"] + out: 0 + - name: "two_identical_palindromes" + in: + words: ["aa", "aa"] + out: 4 + - name: "three_identical_palindromes" + in: + words: ["zz", "zz", "zz"] + out: 6 + - name: "mixed_diagonal_odds" + in: + words: ["aa", "bb", "cc"] + out: 2 + - name: "mixed_diagonal_pairs" + in: + words: ["aa", "aa", "bb", "bb", "cc"] + out: 10 + - name: "reverse_counts_left_heavy" + in: + words: ["ab", "ab", "ab", "ba", "ba"] + out: 8 + - name: "reverse_counts_right_heavy" + in: + words: ["cd", "dc", "dc", "dc"] + out: 4 + - name: "several_pairs" + in: + words: ["ab", "ba", "cd", "dc", "ef", "fe"] + out: 12 + - name: "pairs_and_center" + in: + words: ["ab", "ba", "cc", "dd", "dd"] + out: 10 + - name: "center_consumed_by_pair" + in: + words: ["aa", "aa", "ab", "ba"] + out: 8 + - name: "all_letters_diagonal" + in: + words: ["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo", "pp", "qq", "rr", "ss", "tt", "uu", "vv", "ww", "xx", "yy", "zz"] + out: 2 + - name: "all_letters_two_each" + in: + words: ["aa", "aa", "bb", "bb", "cc", "cc", "dd", "dd", "ee", "ee", "ff", "ff", "gg", "gg", "hh", "hh", "ii", "ii", "jj", "jj", "kk", "kk", "ll", "ll", "mm", "mm", "nn", "nn", "oo", "oo", "pp", "pp", "qq", "qq", "rr", "rr", "ss", "ss", "tt", "tt", "uu", "uu", "vv", "vv", "ww", "ww", "xx", "xx", "yy", "yy", "zz", "zz"] + out: 104 + - name: "lexicographic_pair_boundary" + in: + words: ["az", "za", "ay", "ya", "az", "za"] + out: 12 + - name: "reverse_same_word" + in: + words: ["mn", "nm", "mn", "nm", "oo"] + out: 10 + - name: "duplicates_with_noise" + in: + words: ["ab", "ba", "ab", "xy", "yx", "xy", "cc", "de"] + out: 10 + - name: "no_usable_words" + in: + words: ["ab", "cd", "ef", "gh", "ij"] + out: 0 + - name: "maximum_word_diversity" + in: + words: ["ab", "ba", "ac", "ca", "ad", "da", "ae", "ea", "af", "fa", "ag", "ga", "ah", "ha", "ai", "ia"] + out: 32 + - name: "palindrome_pair_priority" + in: + words: ["aa", "aa", "aa", "bb", "cc", "bc", "cb"] + out: 10 + - name: "odd_palindrome_pool" + in: + words: ["aa", "aa", "aa", "aa", "aa", "bb", "bb", "bb"] + out: 14 + - name: "large_count_small_alphabet" + in: + words: ["ab", "ba", "ab", "ba", "aa", "bb", "aa", "bb", "cc", "cc", "cc"] + out: 22 + - name: "case_order_irrelevant" + in: + words: ["zy", "yx", "xy", "yz", "zz"] + out: 10 + - name: "single_center_among_pairs" + in: + words: ["ab", "ba", "cd", "dc", "ee", "fg", "gf"] + out: 14 + - name: "gen_random_small" + seed: 31 + in: + words: + gen: "array" + len: + gen: "int" + min: 1 + max: 40 + of: + gen: "str" + len: 2 + alphabet: "abcde" + distinct: false + sorted: false + - name: "gen_random_medium" + seed: 32 + in: + words: + gen: "array" + len: + gen: "int" + min: 100 + max: 500 + of: + gen: "str" + len: 2 + alphabet: "abcdefghij" + distinct: false + sorted: false + - name: "gen_maximum_stress" + seed: 33 + in: + words: + gen: "array" + len: 100000 + of: + gen: "str" + len: 2 + alphabet: "abcdefghijklmnopqrstuvwxyz" + distinct: false + sorted: false + - name: "gen_binary_stress" + seed: 34 + in: + words: + gen: "array" + len: 100000 + of: + gen: "str" + len: 2 + alphabet: "ab" + distinct: false + sorted: false + - name: "gen_medium_alphabet" + seed: 35 + in: + words: + gen: "array" + len: + gen: "int" + min: 1000 + max: 3000 + of: + gen: "str" + len: 2 + alphabet: "xyz" + distinct: false + sorted: false diff --git a/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/sol.py b/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/sol.py new file mode 100644 index 00000000..70e25daa --- /dev/null +++ b/tests/2001-2500/2131. longest-palindrome-by-concatenating-two-letter-words/sol.py @@ -0,0 +1,19 @@ +class Solution(object): + def longestPalindrome(self, words): + mpp = [[0]*26 for _ in range(26)] + count = 0 + middle = 0 + for s in words: + x, y = ord(s[0]) - ord('a'), ord(s[1]) - ord('a') + if mpp[y][x] > 0: + mpp[y][x] -= 1 + count += 4 + if x == y: + middle -= 1 + else: + mpp[x][y] += 1 + if x == y: + middle += 1 + if middle > 0: + count += 2 + return count \ No newline at end of file diff --git a/tests/2001-2500/2132. stamping-the-grid/manifest.yaml b/tests/2001-2500/2132. stamping-the-grid/manifest.yaml new file mode 100644 index 00000000..f7766320 --- /dev/null +++ b/tests/2001-2500/2132. stamping-the-grid/manifest.yaml @@ -0,0 +1,473 @@ +entry: + id: 2132 + title: "stamping-the-grid" + params: + grid: + type: array + items: + type: array + items: + type: int + stampHeight: + type: int + stampWidth: + type: int + call: + python3: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + python2: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + cpp: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + rust: "Solution::possible_to_stamp({grid}, {stampHeight}, {stampWidth})" + ruby: "possible_to_stamp({grid}, {stampHeight}, {stampWidth})" + java: "new Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + csharp: "new Solution().PossibleToStamp({grid}, {stampHeight}, {stampWidth})" + kotlin: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + go: "possibleToStamp({grid}, {stampHeight}, {stampWidth})" + dart: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + swift: "Solution().possibleToStamp({grid}, {stampHeight}, {stampWidth})" + typescript: "possibleToStamp({grid}, {stampHeight}, {stampWidth})" + +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 512 +oracle: + python3: + call: "Checker().possibleToStamp(grid, stampHeight, stampWidth, {result})" + checker: | + class Checker: + def possibleToStamp(self, grid, H, W, result): + if not isinstance(result, bool) or not grid or not grid[0]: + return False + m, n = len(grid), len(grid[0]) + if any(not isinstance(row, list) or len(row) != n for row in grid): + return False + ps = [[0] * (n + 1) for _ in range(m + 1)] + for i in range(m): + for j in range(n): + ps[i + 1][j + 1] = grid[i][j] + ps[i][j + 1] + ps[i + 1][j] - ps[i][j] + diff = [[0] * (n + 1) for _ in range(m + 1)] + for i in range(m - H + 1): + for j in range(n - W + 1): + total = ps[i + H][j + W] - ps[i][j + W] - ps[i + H][j] + ps[i][j] + if total == 0: + diff[i][j] += 1 + diff[i + H][j] -= 1 + diff[i][j + W] -= 1 + diff[i + H][j + W] += 1 + expected = True + for i in range(m): + for j in range(n): + if i: + diff[i][j] += diff[i - 1][j] + if j: + diff[i][j] += diff[i][j - 1] + if i and j: + diff[i][j] -= diff[i - 1][j - 1] + if grid[i][j] == 0 and diff[i][j] <= 0: + expected = False + + return result == expected +seed: 2132 +tests: + - name: "example_overlapping" + in: + grid: + - [1, 0, 0, 0] + - [1, 0, 0, 0] + - [1, 0, 0, 0] + - [1, 0, 0, 0] + - [1, 0, 0, 0] + stampHeight: 4 + stampWidth: 3 + out: true + - name: "example_diagonal_blockers" + in: + grid: + - [1, 0, 0, 0] + - [0, 1, 0, 0] + - [0, 0, 1, 0] + - [0, 0, 0, 1] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "single_empty_unit" + in: + grid: + - [0] + stampHeight: 1 + stampWidth: 1 + out: true + - name: "single_occupied_large_stamp" + in: + grid: + - [1] + stampHeight: 9 + stampWidth: 9 + out: true + - name: "single_empty_too_large" + in: + grid: + - [0] + stampHeight: 2 + stampWidth: 1 + out: false + - name: "one_row_exact" + in: + grid: + - [0, 0, 0, 0, 0] + stampHeight: 1 + stampWidth: 3 + out: true + - name: "one_row_gap" + in: + grid: + - [0, 0, 1, 0, 0] + stampHeight: 1 + stampWidth: 2 + out: true + - name: "one_row_isolated_left" + in: + grid: + - [0, 1, 0] + stampHeight: 1 + stampWidth: 2 + out: false + - name: "one_column_exact" + in: + grid: + - [0] + - [0] + - [0] + - [0] + stampHeight: 3 + stampWidth: 1 + out: true + - name: "one_column_gap" + in: + grid: + - [0] + - [1] + - [0] + stampHeight: 2 + stampWidth: 1 + out: false + - name: "all_occupied" + in: + grid: + - [1, 1, 1] + - [1, 1, 1] + stampHeight: 5 + stampWidth: 5 + out: true + - name: "empty_rectangle_exact" + in: + grid: + - [0, 0, 0] + - [0, 0, 0] + stampHeight: 2 + stampWidth: 3 + out: true + - name: "empty_rectangle_height_miss" + in: + grid: + - [0, 0, 0] + - [0, 0, 0] + stampHeight: 3 + stampWidth: 2 + out: false + - name: "empty_rectangle_width_miss" + in: + grid: + - [0, 0] + - [0, 0] + stampHeight: 1 + stampWidth: 3 + out: false + - name: "unit_stamps_cover_all" + in: + grid: + - [0, 1, 0] + - [1, 0, 1] + stampHeight: 1 + stampWidth: 1 + out: true + - name: "horizontal_bar_obstacle" + in: + grid: + - [0, 0, 0, 0] + - [1, 1, 1, 1] + - [0, 0, 0, 0] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "vertical_bar_obstacle" + in: + grid: + - [0, 1, 0] + - [0, 1, 0] + - [0, 1, 0] + stampHeight: 2 + stampWidth: 1 + out: true + - name: "corner_occupied" + in: + grid: + - [1, 0, 0] + - [0, 0, 0] + - [0, 0, 0] + stampHeight: 2 + stampWidth: 2 + out: true + - name: "cross_obstacles" + in: + grid: + - [0, 1, 0] + - [1, 1, 1] + - [0, 1, 0] + stampHeight: 1 + stampWidth: 1 + out: true + - name: "cross_requires_overlap" + in: + grid: + - [0, 1, 0] + - [1, 0, 1] + - [0, 1, 0] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "two_by_two_one_empty" + in: + grid: + - [1, 1] + - [1, 0] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "two_by_two_one_empty_unit" + in: + grid: + - [1, 1] + - [1, 0] + stampHeight: 1 + stampWidth: 1 + out: true + - name: "checkerboard_two" + in: + grid: + - [0, 1, 0, 1] + - [1, 0, 1, 0] + - [0, 1, 0, 1] + - [1, 0, 1, 0] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "checkerboard_unit" + in: + grid: + - [0, 1, 0, 1] + - [1, 0, 1, 0] + - [0, 1, 0, 1] + - [1, 0, 1, 0] + stampHeight: 1 + stampWidth: 1 + out: true + - name: "full_width_single_row" + in: + grid: + - [0, 0, 1, 0, 0] + - [0, 0, 0, 0, 0] + stampHeight: 1 + stampWidth: 5 + out: false + - name: "full_height_single_column" + in: + grid: + - [0, 0] + - [0, 1] + - [0, 0] + - [0, 0] + stampHeight: 4 + stampWidth: 1 + out: false + - name: "large_stamp_fits_open_window" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 0, 0, 0, 1] + - [1, 0, 0, 0, 1] + - [1, 1, 1, 1, 1] + stampHeight: 2 + stampWidth: 3 + out: true + - name: "large_stamp_window_blocked" + in: + grid: + - [1, 1, 1, 1, 1] + - [1, 0, 1, 0, 1] + - [1, 0, 0, 0, 1] + - [1, 1, 1, 1, 1] + stampHeight: 2 + stampWidth: 3 + out: false + - name: "overlap_horizontal" + in: + grid: + - [1, 0, 0, 0, 0, 1] + - [1, 0, 0, 0, 0, 1] + stampHeight: 2 + stampWidth: 4 + out: true + - name: "overlap_vertical" + in: + grid: + - [1, 1] + - [0, 0] + - [0, 0] + - [0, 0] + - [1, 1] + stampHeight: 4 + stampWidth: 1 + out: false + - name: "stamp_one_by_many" + in: + grid: + - [0, 0, 1, 0, 0, 0] + stampHeight: 1 + stampWidth: 2 + out: true + - name: "stamp_many_by_one" + in: + grid: + - [0] + - [0] + - [1] + - [0] + - [0] + stampHeight: 2 + stampWidth: 1 + out: true + - name: "all_empty_three_by_three" + in: + grid: + - [0, 0, 0] + - [0, 0, 0] + - [0, 0, 0] + stampHeight: 2 + stampWidth: 2 + out: true + - name: "isolated_empty_between_walls" + in: + grid: + - [1, 1, 1] + - [1, 0, 1] + - [1, 1, 1] + stampHeight: 2 + stampWidth: 2 + out: false + - name: "generated_small" + seed: 31 + in: + grid: + gen: "array" + len: 5 + of: + gen: "array" + len: 6 + of: + gen: "int" + min: 0 + max: 1 + stampHeight: + gen: "int" + min: 1 + max: 6 + stampWidth: + gen: "int" + min: 1 + max: 6 + - name: "generated_medium" + seed: 32 + in: + grid: + gen: "array" + len: 40 + of: + gen: "array" + len: 50 + of: + gen: "int" + min: 0 + max: 1 + stampHeight: + gen: "int" + min: 1 + max: 40 + stampWidth: + gen: "int" + min: 1 + max: 50 + - name: "generated_wide_stress" + seed: 33 + in: + grid: + gen: "array" + len: 2 + of: + gen: "array" + len: 1000 + of: + gen: "int" + min: 0 + max: 1 + stampHeight: + gen: "int" + min: 1 + max: 2 + stampWidth: + gen: "int" + min: 1 + max: 1000 + - name: "generated_tall_stress" + seed: 34 + in: + grid: + gen: "array" + len: 1000 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 0 + max: 1 + stampHeight: + gen: "int" + min: 1 + max: 1000 + stampWidth: + gen: "int" + min: 1 + max: 2 + - name: "generated_square_stress" + seed: 35 + in: + grid: + gen: "array" + len: 30 + of: + gen: "array" + len: 30 + of: + gen: "int" + min: 0 + max: 1 + stampHeight: + gen: "int" + min: 1 + max: 30 + stampWidth: + gen: "int" + min: 1 + max: 30 diff --git a/tests/2001-2500/2132. stamping-the-grid/sol.py b/tests/2001-2500/2132. stamping-the-grid/sol.py new file mode 100644 index 00000000..d2e70b46 --- /dev/null +++ b/tests/2001-2500/2132. stamping-the-grid/sol.py @@ -0,0 +1,34 @@ +class Solution: + def possibleToStamp(self, grid: List[List[int]], stampHeight: int, stampWidth: int) -> bool: + m, n = len(grid),len(grid[0]) + H,W = stampHeight,stampWidth + + # Build Prefix sums + ps = [[0] * (n+1) for _ in range(m+1)] + for i in range(m): + for j in range(n): + ps[i+1][j+1] = ps[i][j+1] + ps[i+1][j] - ps[i][j] + grid[i][j] + + # Difference Array + diff = [[0] * (n+1) for _ in range(m+1)] + for i in range(m - H + 1): + for j in range(n - W + 1): + total = ps[i+H][j + W] - ps[i][j + W] - ps[i + H][j] + ps[i][j] + if total == 0: + diff[i][j] += 1 + diff[i+H][j] -= 1 + diff[i][j+W] -= 1 + diff[i+H][j+W] += 1 + # Reconstruct coverage + for i in range(m): + for j in range(n): + if i > 0: diff[i][j] += diff[i-1][j] + if j > 0: diff[i][j] += diff[i][j-1] + if i > 0 and j > 0: diff[i][j] -= diff[i-1][j-1] + + # Check validity + for i in range(m): + for j in range(n): + if grid[i][j] == 0 and diff[i][j] <= 0: + return False + return True \ No newline at end of file diff --git a/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/manifest.yaml b/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/manifest.yaml new file mode 100644 index 00000000..de703a6d --- /dev/null +++ b/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/manifest.yaml @@ -0,0 +1,429 @@ +entry: + id: 2133 + title: "check-if-every-row-and-column-contains-all-numbers" + params: + matrix: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().checkValid({matrix})" + rust: "Solution::check_valid({matrix})" + python3: "Solution().checkValid({matrix})" + python2: "Solution().checkValid({matrix})" + ruby: "check_valid({matrix})" + java: "new Solution().checkValid({matrix})" + csharp: "new Solution().CheckValid({matrix})" + kotlin: "Solution().checkValid({matrix})" + go: "checkValid({matrix})" + dart: "Solution().checkValid({matrix})" + swift: "Solution().checkValid({matrix})" + typescript: "checkValid({matrix})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().checkValid(matrix, {result})" + checker: | + class Checker: + def checkValid(self, matrix, result): + if not isinstance(result, bool): + return False + n = len(matrix) + expected = set(range(1, n + 1)) + valid = all(set(row) == expected for row in matrix) + valid = valid and all(set(matrix[i][j] for i in range(n)) == expected for j in range(n)) + return result == valid + +seed: 2133 + +tests: + - name: "example_1_valid_3" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3] + - [3, 1, 2] + - [2, 3, 1] + out: true + - name: "example_2_duplicate_row" + in: + matrix: + elemType: "int" + value: + - [1, 1, 1] + - [1, 2, 3] + - [1, 2, 3] + out: false + - name: "single_cell" + in: + matrix: + elemType: "int" + value: + - [1] + out: true + - name: "two_valid" + in: + matrix: + elemType: "int" + value: + - [1, 2] + - [2, 1] + out: true + - name: "two_duplicate" + in: + matrix: + elemType: "int" + value: + - [1, 1] + - [2, 2] + out: false + - name: "two_column_failure" + in: + matrix: + elemType: "int" + value: + - [1, 2] + - [1, 2] + out: false + - name: "three_cyclic_shift" + in: + matrix: + elemType: "int" + value: + - [2, 3, 1] + - [3, 1, 2] + - [1, 2, 3] + out: true + - name: "three_missing_one" + in: + matrix: + elemType: "int" + value: + - [1, 2, 2] + - [2, 3, 1] + - [3, 1, 2] + out: false + - name: "three_row_only_failure" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3] + - [2, 3, 1] + - [1, 2, 3] + out: false + - name: "three_column_only_failure" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3] + - [3, 1, 2] + - [3, 2, 1] + out: false + - name: "four_cyclic" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4] + - [2, 3, 4, 1] + - [3, 4, 1, 2] + - [4, 1, 2, 3] + out: true + - name: "four_reversed_rows" + in: + matrix: + elemType: "int" + value: + - [4, 3, 2, 1] + - [3, 2, 1, 4] + - [2, 1, 4, 3] + - [1, 4, 3, 2] + out: true + - name: "four_duplicate_corner" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 1] + - [2, 3, 4, 1] + - [3, 4, 1, 2] + - [4, 1, 2, 3] + out: false + - name: "four_missing_middle" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4] + - [2, 2, 4, 1] + - [3, 4, 1, 2] + - [4, 1, 2, 3] + out: false + - name: "four_column_duplicate" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4] + - [2, 3, 4, 1] + - [3, 4, 1, 2] + - [3, 1, 2, 4] + out: false + - name: "five_cyclic" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5] + - [2, 3, 4, 5, 1] + - [3, 4, 5, 1, 2] + - [4, 5, 1, 2, 3] + - [5, 1, 2, 3, 4] + out: true + - name: "five_reverse_cyclic" + in: + matrix: + elemType: "int" + value: + - [5, 4, 3, 2, 1] + - [4, 3, 2, 1, 5] + - [3, 2, 1, 5, 4] + - [2, 1, 5, 4, 3] + - [1, 5, 4, 3, 2] + out: true + - name: "five_duplicate_one" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 4] + - [2, 3, 4, 5, 1] + - [3, 4, 5, 1, 2] + - [4, 5, 1, 2, 3] + - [5, 1, 2, 3, 4] + out: false + - name: "five_bad_last_row" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5] + - [2, 3, 4, 5, 1] + - [3, 4, 5, 1, 2] + - [4, 5, 1, 2, 3] + - [5, 5, 2, 3, 4] + out: false + - name: "five_bad_column" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5] + - [2, 3, 4, 5, 1] + - [3, 4, 5, 1, 2] + - [4, 5, 1, 2, 3] + - [5, 1, 2, 4, 4] + out: false + - name: "six_cyclic" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6] + - [2, 3, 4, 5, 6, 1] + - [3, 4, 5, 6, 1, 2] + - [4, 5, 6, 1, 2, 3] + - [5, 6, 1, 2, 3, 4] + - [6, 1, 2, 3, 4, 5] + out: true + - name: "six_row_permutation" + in: + matrix: + elemType: "int" + value: + - [3, 4, 5, 6, 1, 2] + - [1, 2, 3, 4, 5, 6] + - [6, 1, 2, 3, 4, 5] + - [2, 3, 4, 5, 6, 1] + - [5, 6, 1, 2, 3, 4] + - [4, 5, 6, 1, 2, 3] + out: true + - name: "six_duplicate" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6] + - [2, 3, 4, 5, 6, 1] + - [3, 4, 5, 6, 1, 2] + - [4, 5, 6, 1, 2, 3] + - [5, 6, 1, 2, 3, 4] + - [6, 1, 2, 3, 3, 5] + out: false + - name: "six_wrong_value_pattern" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6] + - [2, 3, 4, 5, 6, 1] + - [3, 4, 5, 6, 1, 2] + - [4, 5, 6, 1, 2, 3] + - [5, 6, 1, 2, 3, 4] + - [6, 1, 2, 3, 4, 4] + out: false + - name: "one_hundred_all_ones" + seed: 1001 + in: + matrix: + gen: "array" + len: 100 + elemType: "int" + of: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 1 + - name: "one_hundred_random_values" + seed: 1002 + in: + matrix: + gen: "array" + len: 100 + elemType: "int" + of: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + - name: "ninety_nine_random_values" + seed: 1003 + in: + matrix: + gen: "array" + len: 99 + elemType: "int" + of: + gen: "array" + len: 99 + of: + gen: "int" + min: 1 + max: 99 + - name: "seventy_three_random_values" + seed: 1004 + in: + matrix: + gen: "array" + len: 73 + elemType: "int" + of: + gen: "array" + len: 73 + of: + gen: "int" + min: 1 + max: 73 + - name: "fifty_random_values" + seed: 1005 + in: + matrix: + gen: "array" + len: 50 + elemType: "int" + of: + gen: "array" + len: 50 + of: + gen: "int" + min: 1 + max: 50 + - name: "seven_cyclic" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6, 7] + - [2, 3, 4, 5, 6, 7, 1] + - [3, 4, 5, 6, 7, 1, 2] + - [4, 5, 6, 7, 1, 2, 3] + - [5, 6, 7, 1, 2, 3, 4] + - [6, 7, 1, 2, 3, 4, 5] + - [7, 1, 2, 3, 4, 5, 6] + out: true + - name: "seven_bad_first_row" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6, 6] + - [2, 3, 4, 5, 6, 7, 1] + - [3, 4, 5, 6, 7, 1, 2] + - [4, 5, 6, 7, 1, 2, 3] + - [5, 6, 7, 1, 2, 3, 4] + - [6, 7, 1, 2, 3, 4, 5] + - [7, 1, 2, 3, 4, 5, 6] + out: false + - name: "eight_cyclic" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6, 7, 8] + - [2, 3, 4, 5, 6, 7, 8, 1] + - [3, 4, 5, 6, 7, 8, 1, 2] + - [4, 5, 6, 7, 8, 1, 2, 3] + - [5, 6, 7, 8, 1, 2, 3, 4] + - [6, 7, 8, 1, 2, 3, 4, 5] + - [7, 8, 1, 2, 3, 4, 5, 6] + - [8, 1, 2, 3, 4, 5, 6, 7] + out: true + - name: "eight_bad_diagonal" + in: + matrix: + elemType: "int" + value: + - [1, 2, 3, 4, 5, 6, 7, 8] + - [2, 3, 4, 5, 6, 7, 8, 1] + - [3, 4, 5, 6, 7, 8, 1, 2] + - [4, 5, 6, 7, 8, 1, 2, 3] + - [5, 6, 7, 8, 1, 2, 3, 4] + - [6, 7, 8, 1, 2, 3, 4, 5] + - [7, 8, 1, 2, 3, 4, 5, 6] + - [8, 1, 2, 3, 4, 5, 6, 6] + out: false + - name: "three_permuted_rows" + in: + matrix: + elemType: "int" + value: + - [2, 3, 1] + - [1, 2, 3] + - [3, 1, 2] + out: true + - name: "four_transposed_valid" + in: + matrix: + elemType: "int" + value: + - [1, 4, 3, 2] + - [2, 1, 4, 3] + - [3, 2, 1, 4] + - [4, 3, 2, 1] + out: true diff --git a/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/sol.py b/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/sol.py new file mode 100644 index 00000000..037455de --- /dev/null +++ b/tests/2001-2500/2133. check-if-every-row-and-column-contains-all-numbers/sol.py @@ -0,0 +1,18 @@ +class Solution: + def checkValid(self, matrix): + n = len(matrix) + for i in range(n): + for j in range(n): + pos = abs(matrix[i][j]) - 1 + if matrix[i][pos] < 0: + return False + matrix[i][pos] = -matrix[i][pos] + + for j in range(n): + for i in range(n): + pos = abs(matrix[i][j]) - 1 + if matrix[pos][j] > 0: + return False + matrix[pos][j] = abs(matrix[pos][j]) + + return True \ No newline at end of file diff --git a/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/manifest.yaml b/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/manifest.yaml new file mode 100644 index 00000000..f3b87522 --- /dev/null +++ b/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/manifest.yaml @@ -0,0 +1,207 @@ +entry: + id: 2134 + title: "minimum-swaps-to-group-all-1s-together-ii" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().minSwaps({nums})" + rust: "Solution::min_swaps({nums})" + python3: "Solution().minSwaps({nums})" + python2: "Solution().minSwaps({nums})" + ruby: "min_swaps({nums})" + java: "new Solution().minSwaps({nums})" + csharp: "new Solution().MinSwaps({nums})" + kotlin: "Solution().minSwaps({nums})" + go: "minSwaps({nums})" + dart: "Solution().minSwaps({nums})" + swift: "Solution().minSwaps({nums})" + typescript: "minSwaps({nums})" + +judge: + type: "exact" + +limits: + time_ms: 5000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().check(nums, {result})" + checker: | + class Checker: + def check(self, nums, result): + n = len(nums) + ones = sum(nums) + if not isinstance(result, int) or isinstance(result, bool): + return False + if ones <= 1 or ones == n: + return result == 0 + doubled = nums + nums[:ones - 1] + inside = sum(doubled[:ones]) + best = ones - inside + for i in range(ones, len(doubled)): + inside += doubled[i] - doubled[i - ones] + best = min(best, ones - inside) + return result == best + +seed: 2134 + +tests: + - name: "example_1" + in: + nums: [0, 1, 0, 1, 1, 0, 0] + - name: "example_2" + in: + nums: [0, 1, 1, 1, 0, 0, 1, 1, 0] + - name: "example_3" + in: + nums: [1, 1, 0, 0, 1] + - name: "single_zero" + in: + nums: [0] + - name: "single_one" + in: + nums: [1] + - name: "two_zeros" + in: + nums: [0, 0] + - name: "two_ones" + in: + nums: [1, 1] + - name: "alternating_even" + in: + nums: [1, 0, 1, 0, 1, 0, 1, 0] + - name: "alternating_odd" + in: + nums: [0, 1, 0, 1, 0, 1, 0] + - name: "ones_at_wrap" + in: + nums: [1, 1, 0, 0, 0, 1] + - name: "zeros_at_wrap" + in: + nums: [0, 1, 1, 1, 1, 0] + - name: "one_zero_gap" + in: + nums: [1, 0, 1] + - name: "one_one_gap" + in: + nums: [0, 1, 0, 1] + - name: "already_grouped_start" + in: + nums: [1, 1, 1, 0, 0, 0, 0] + - name: "already_grouped_middle" + in: + nums: [0, 0, 1, 1, 1, 0, 0] + - name: "all_zeros_small" + in: + nums: [0, 0, 0, 0, 0] + - name: "all_ones_small" + in: + nums: [1, 1, 1, 1, 1] + - name: "mostly_ones" + in: + nums: [1, 0, 1, 1, 1, 0, 1, 1] + - name: "mostly_zeros" + in: + nums: [0, 1, 0, 0, 0, 1, 0, 0] + - name: "symmetric" + in: + nums: [1, 0, 0, 1, 0, 0, 1] + - name: "cluster_split_by_end" + in: + nums: [1, 0, 0, 1, 1, 0, 0, 1] + - name: "long_run_center" + in: + nums: [0, 0, 0, 1, 1, 1, 1, 1, 0, 0] + - name: "long_run_wrap" + in: + nums: [1, 1, 1, 0, 0, 0, 0, 1, 1] + - name: "sparse_ones" + in: + nums: [1, 0, 0, 0, 0, 1, 0, 0, 1, 0] + - name: "sparse_zeros" + in: + nums: [0, 1, 1, 1, 1, 0, 1, 1, 1, 1] + - name: "prime_length" + in: + nums: [0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0] + - name: "length_twelve" + in: + nums: [1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1] + - name: "dense_alternating" + in: + nums: [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1] + - name: "boundary_one_at_each_end" + in: + nums: [1, 0, 0, 0, 0, 0, 1] + - name: "boundary_zero_at_each_end" + in: + nums: [0, 1, 1, 1, 1, 1, 0] + - name: "generated_small" + seed: 301 + in: + nums: + gen: "array" + len: + gen: "int" + min: 1 + max: 25 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_medium" + seed: 302 + in: + nums: + gen: "array" + len: + gen: "int" + min: 50 + max: 250 + of: + gen: "int" + min: 0 + max: 1 + - name: "generated_sparse" + seed: 303 + in: + nums: + gen: "array" + len: + gen: "int" + min: 500 + max: 1000 + of: + gen: "int" + min: 0 + max: 1 + - name: "stress_large_balanced" + seed: 304 + in: + nums: + gen: "array" + len: + gen: "int" + min: 50000 + max: 50000 + of: + gen: "int" + min: 0 + max: 1 + - name: "stress_maximum" + seed: 305 + in: + nums: + gen: "array" + len: + gen: "int" + min: 100000 + max: 100000 + of: + gen: "int" + min: 0 + max: 1 diff --git a/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/sol.py b/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/sol.py new file mode 100644 index 00000000..f0a896de --- /dev/null +++ b/tests/2001-2500/2134. minimum-swaps-to-group-all-1s-together-ii/sol.py @@ -0,0 +1,21 @@ +class Solution: + def solve(self, n, nums): + win, count = 0, 0 + for num in nums: + if num == n: + win += 1 + for i in range(win): + if nums[i] == n: + count += 1 + res = win - count + for i in range(win,len(nums)): + if nums[i] == n: + count += 1 + if nums[i-win] == n: + count -= 1 + res = min(res, win - count) + return res + def minSwaps(self, nums: List[int]) -> int: + res1 = self.solve(1,nums) + res2 = self.solve(0,nums) + return min(res1,res2) \ No newline at end of file diff --git a/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/manifest.yaml b/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/manifest.yaml new file mode 100644 index 00000000..0324e9d1 --- /dev/null +++ b/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/manifest.yaml @@ -0,0 +1,343 @@ +entry: + id: 2135 + title: "count-words-obtained-after-adding-a-letter" + params: + startWords: + type: array + items: + type: string + targetWords: + type: array + items: + type: string + call: + cpp: "Solution().wordCount({startWords}, {targetWords})" + rust: "Solution::word_count({startWords}, {targetWords})" + python3: "Solution().wordCount({startWords}, {targetWords})" + python2: "Solution().wordCount({startWords}, {targetWords})" + ruby: "word_count({startWords}, {targetWords})" + java: "new Solution().wordCount({startWords}, {targetWords})" + csharp: "new Solution().WordCount({startWords}, {targetWords})" + kotlin: "Solution().wordCount({startWords}, {targetWords})" + go: "wordCount({startWords}, {targetWords})" + dart: "Solution().wordCount({startWords}, {targetWords})" + swift: "Solution().wordCount({startWords}, {targetWords})" + typescript: "wordCount({startWords}, {targetWords})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().wordCount(startWords, targetWords, {result})" + checker: | + class Checker: + def wordCount(self, startWords, targetWords, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + available = {''.join(sorted(word)) for word in startWords} + expected = 0 + for target in targetWords: + for index, letter in enumerate(target): + if target.count(letter) == 1 and target[:index] + target[index + 1:] in available: + expected += 1 + break + return result == expected + +seed: 2135 + +tests: + - name: "example_one" + in: + startWords: ["ant", "act", "tack"] + targetWords: ["tack", "act", "acti"] + out: 2 + - name: "example_two" + in: + startWords: ["ab", "a"] + targetWords: ["abc", "abcd"] + out: 1 + - name: "single_match" + in: + startWords: ["a"] + targetWords: ["ab"] + out: 1 + - name: "single_no_match_same_word" + in: + startWords: ["a"] + targetWords: ["a"] + out: 0 + - name: "single_letter_impossible" + in: + startWords: ["z"] + targetWords: ["a"] + out: 0 + - name: "empty_intersection" + in: + startWords: ["abc", "def"] + targetWords: ["ghi", "jkl"] + out: 0 + - name: "rearrangement_match" + in: + startWords: ["abc"] + targetWords: ["dbca"] + out: 1 + - name: "rearrangement_without_added_letter" + in: + startWords: ["abc"] + targetWords: ["cba"] + out: 0 + - name: "added_letter_already_present" + in: + startWords: ["abc"] + targetWords: ["abca"] + out: 0 + - name: "multiple_possible_starts" + in: + startWords: ["ab", "ac", "bc"] + targetWords: ["abc", "abd", "acd"] + out: 3 + - name: "target_duplicates_count_separately" + in: + startWords: ["ab"] + targetWords: ["abc", "cba", "abc", "bca"] + out: 4 + - name: "start_duplicates_are_harmless" + in: + startWords: ["ab", "ba", "ab"] + targetWords: ["abc", "acb", "abcd"] + out: 2 + - name: "one_letter_from_each_length" + in: + startWords: ["a", "ab", "abc", "abcd"] + targetWords: ["ab", "abc", "abcd", "abcde", "abcdef"] + out: 4 + - name: "long_chain" + in: + startWords: ["a", "ab", "abc", "abcd", "abcde", "abcdef", "abcdefg", "abcdefgh"] + targetWords: ["ba", "cba", "dcba", "edcba", "fedcba", "gfedcba", "hgfedcba", "ihgfedcba"] + out: 8 + - name: "alphabet_prefix" + in: + startWords: ["abcdefghijklmnopqrstuvwxy"] + targetWords: ["zyxwvutsrqponmlkjihgfedcba", "yxwvutsrqponmlkjihgfedcbaz", "abcdefghijklmnopqrstuvwxy"] + out: 2 + - name: "alphabet_missing_each_end" + in: + startWords: ["bcdefghijklmnopqrstuvwxyz", "acdefghijklmnopqrstuvwxyz"] + targetWords: ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcb", "abcdefghijklmnopqrstuvwxy"] + out: 1 + - name: "mixed_lengths" + in: + startWords: ["x", "yz", "mnop", "rstuv", "abcdefghij"] + targetWords: ["xy", "zyx", "mnopq", "vutsrq", "abcdefghijk", "mnopqrst"] + out: 5 + - name: "same_signature_different_order" + in: + startWords: ["cab", "fed", "jih"] + targetWords: ["abcd", "defg", "ghij", "abc"] + out: 3 + - name: "only_repeated_target_candidate" + in: + startWords: ["ab"] + targetWords: ["aab", "abb", "aba", "abc"] + out: 1 + - name: "all_candidates_repeated" + in: + startWords: ["a", "b", "c"] + targetWords: ["aa", "bb", "cc", "ab", "bc"] + out: 2 + - name: "near_full_start_set" + in: + startWords: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] + targetWords: ["ab", "bc", "jk", "ka", "zz", "aa"] + out: 4 + - name: "disjoint_lengths" + in: + startWords: ["a", "b", "c"] + targetWords: ["abcd", "efgh", "ijklm"] + out: 0 + - name: "long_single_target" + in: + startWords: ["abcdefghijklmnopqrstuvwx"] + targetWords: ["zyxwvutsrqponmlkjihgfedcba"] + out: 0 + - name: "target_order_irrelevant" + in: + startWords: ["dog", "cat"] + targetWords: ["zcat", "doge", "tacx", "god", "cat"] + out: 3 + - name: "single_start_many_targets" + in: + startWords: ["a"] + targetWords: ["ab", "ac", "ad", "ba", "ca", "a"] + out: 5 + - name: "nested_rearrangement" + in: + startWords: ["ace", "bdf", "gh"] + targetWords: ["face", "aced", "bdfe", "hgi", "ghi"] + out: 5 + - name: "boundary_length_two" + in: + startWords: ["qwertyuiopasdfghjklzxcvbnm"] + targetWords: ["qwertyuiopasdfghjklzxcvbnma", "qwertyuiopasdfghjklzxcvbn"] + out: 0 + - name: "case_sensitive_alphabet_only" + in: + startWords: ["mnop", "qrst"] + targetWords: ["mnopq", "qrstu", "nopm", "rstq"] + out: 2 + - name: "several_added_choices" + in: + startWords: ["ab", "cd", "ef", "gh"] + targetWords: ["abc", "abd", "cde", "cdf", "efg", "egh", "ghi", "ghz"] + out: 8 + - name: "long_start_and_short_targets" + in: + startWords: ["abcdefghijklmnopqrstuvwx", "yz"] + targetWords: ["abcdefghijklmnopqrstuvwxy", "xyz", "yz", "abcdefghijklmnopqrstuvwx"] + out: 2 + - name: "all_twenty_six_letters" + in: + startWords: ["abcdefghijklmnopqrstuvwxyz"] + targetWords: ["abcdefghijklmnopqrstuvwxyz", "bcdefghijklmnopqrstuvwxyza"] + out: 0 + - name: "generated_small_words" + seed: 101 + in: + startWords: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefgh" + distinct: true + elemType: "string" + targetWords: + gen: "array" + len: + gen: "int" + min: 1 + max: 30 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefghi" + distinct: false + elemType: "string" + - name: "generated_medium_words" + seed: 202 + in: + startWords: + gen: "array" + len: 200 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefghijklmno" + distinct: false + elemType: "string" + targetWords: + gen: "array" + len: 250 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefghijklmnop" + distinct: false + elemType: "string" + - name: "generated_large_words" + seed: 303 + in: + startWords: + gen: "array" + len: 50000 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefghijklmnopqrstuvwxyz" + distinct: false + elemType: "string" + targetWords: + gen: "array" + len: 50000 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefghijklmnopqrstuvwxyz" + distinct: false + elemType: "string" + - name: "generated_large_short_words" + seed: 404 + in: + startWords: + gen: "array" + len: 50000 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdef" + distinct: false + elemType: "string" + targetWords: + gen: "array" + len: 50000 + of: + gen: "str" + len: + gen: "int" + min: 1 + max: 1 + alphabet: "abcdefg" + distinct: false + elemType: "string" + - name: "generated_full_alphabet" + seed: 505 + in: + startWords: + gen: "array" + len: 1000 + of: + gen: "str" + len: 1 + alphabet: "abcdefghijklmnopqrstuvwxyz" + distinct: false + elemType: "string" + targetWords: + gen: "array" + len: 1000 + of: + gen: "str" + len: 1 + alphabet: "abcdefghijklmnopqrstuvwxyz" + distinct: false + elemType: "string" diff --git a/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/sol.py b/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/sol.py new file mode 100644 index 00000000..52672750 --- /dev/null +++ b/tests/2001-2500/2135. count-words-obtained-after-adding-a-letter/sol.py @@ -0,0 +1,21 @@ +from collections import Counter + +class Solution: + def wordCount(self, startWords: List[str], targetWords: List[str]) -> int: + store = set() + for w in startWords: + store.add(''.join(sorted(list(w)))) + + answer = 0 + + for t in targetWords: + counts = Counter(t) + sorti = ''.join(sorted(list(t))) + for i in range(len(sorti)): + if counts[sorti[i]] == 1: + new = sorti[:i] + sorti[i+1:] + if new in store: + answer += 1 + break + + return answer \ No newline at end of file diff --git a/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/manifest.yaml b/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/manifest.yaml new file mode 100644 index 00000000..dab97ea4 --- /dev/null +++ b/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/manifest.yaml @@ -0,0 +1,302 @@ +entry: + id: 2136 + title: "earliest-possible-day-of-full-bloom" + params: + plantTime: + type: array + items: + type: int + growTime: + type: array + items: + type: int + call: + cpp: "Solution().earliestFullBloom({plantTime}, {growTime})" + rust: "Solution::earliest_full_bloom({plantTime}, {growTime})" + python3: "Solution().earliestFullBloom({plantTime}, {growTime})" + python2: "Solution().earliestFullBloom({plantTime}, {growTime})" + ruby: "earliest_full_bloom({plantTime}, {growTime})" + java: "new Solution().earliestFullBloom({plantTime}, {growTime})" + csharp: "new Solution().EarliestFullBloom({plantTime}, {growTime})" + kotlin: "Solution().earliestFullBloom({plantTime}, {growTime})" + go: "earliestFullBloom({plantTime}, {growTime})" + dart: "Solution().earliestFullBloom({plantTime}, {growTime})" + swift: "Solution().earliestFullBloom({plantTime}, {growTime})" + typescript: "earliestFullBloom({plantTime}, {growTime})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().earliestFullBloom(plantTime, growTime, {result})" + checker: | + class Checker: + def earliestFullBloom(self, plantTime, growTime, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + if not isinstance(plantTime, list) or not isinstance(growTime, list): + return False + if len(plantTime) != len(growTime) or not (1 <= len(plantTime) <= 100000): + return False + if any(not isinstance(x, int) or isinstance(x, bool) or not 1 <= x <= 10000 for x in plantTime + growTime): + return False + elapsed = 0 + answer = 0 + for grow, plant in sorted(zip(growTime, plantTime), reverse=True): + elapsed += plant + answer = max(answer, elapsed + grow) + return result == answer + +seed: 2136 + +tests: + - name: "example_1" + in: + plantTime: [1, 4, 3] + growTime: [2, 3, 1] + out: 9 + - name: "example_2" + in: + plantTime: [1, 2, 3, 2] + growTime: [2, 1, 2, 1] + out: 9 + - name: "example_3" + in: + plantTime: [1] + growTime: [1] + out: 2 + - name: "single_max_growth" + in: + plantTime: [5] + growTime: [10000] + out: 10005 + - name: "single_max_plant" + in: + plantTime: [10000] + growTime: [1] + out: 10001 + - name: "equal_small" + in: + plantTime: [1, 1, 1] + growTime: [1, 1, 1] + out: 4 + - name: "equal_pair" + in: + plantTime: [2, 2] + growTime: [3, 3] + out: 7 + - name: "reverse_priority" + in: + plantTime: [1, 2] + growTime: [2, 1] + out: 4 + - name: "long_plant_last" + in: + plantTime: [10, 1, 1] + growTime: [1, 10, 1] + out: 13 + - name: "long_growth_last" + in: + plantTime: [1, 10, 1] + growTime: [1, 1, 10] + out: 13 + - name: "four_mixed" + in: + plantTime: [3, 1, 2, 4] + growTime: [2, 5, 1, 3] + out: 11 + - name: "four_reverse" + in: + plantTime: [4, 3, 2, 1] + growTime: [1, 2, 3, 4] + out: 11 + - name: "three_mixed" + in: + plantTime: [7, 2, 5] + growTime: [6, 9, 1] + out: 15 + - name: "four_varied" + in: + plantTime: [1, 5, 2, 4] + growTime: [10, 2, 8, 1] + out: 13 + - name: "five_varied" + in: + plantTime: [6, 1, 3, 2, 5] + growTime: [4, 7, 2, 9, 1] + out: 18 + - name: "four_high_growth" + in: + plantTime: [2, 9, 1, 8] + growTime: [7, 3, 10, 2] + out: 22 + - name: "equal_plant_increasing_growth" + in: + plantTime: [10, 10, 10] + growTime: [1, 2, 3] + out: 31 + - name: "increasing_plant_equal_growth" + in: + plantTime: [1, 2, 3] + growTime: [10, 10, 10] + out: 16 + - name: "two_max_values" + in: + plantTime: [9999, 10000] + growTime: [10000, 9999] + out: 29998 + - name: "two_max_reversed" + in: + plantTime: [10000, 9999] + growTime: [9999, 10000] + out: 29998 + - name: "five_balanced" + in: + plantTime: [2, 4, 6, 8, 10] + growTime: [10, 8, 6, 4, 2] + out: 32 + - name: "five_balanced_reverse" + in: + plantTime: [10, 8, 6, 4, 2] + growTime: [2, 4, 6, 8, 10] + out: 32 + - name: "alternating_short" + in: + plantTime: [1, 3, 1, 3, 1] + growTime: [5, 1, 4, 2, 3] + out: 10 + - name: "alternating_long" + in: + plantTime: [3, 1, 3, 1, 3] + growTime: [1, 5, 2, 4, 3] + out: 12 + - name: "large_pair_a" + in: + plantTime: [100, 1, 100] + growTime: [1, 100, 1] + out: 202 + - name: "large_pair_b" + in: + plantTime: [1, 100, 1] + growTime: [100, 1, 100] + out: 103 + - name: "descending_plant" + in: + plantTime: [50, 40, 30, 20, 10] + growTime: [5, 15, 25, 35, 45] + out: 155 + - name: "ascending_plant" + in: + plantTime: [5, 15, 25, 35, 45] + growTime: [50, 40, 30, 20, 10] + out: 135 + - name: "growth_dominates" + in: + plantTime: [1, 1, 10, 10] + growTime: [100, 99, 2, 1] + out: 101 + - name: "growth_dominates_reverse" + in: + plantTime: [10, 10, 1, 1] + growTime: [1, 2, 99, 100] + out: 101 + - name: "six_mixed_a" + in: + plantTime: [8, 1, 7, 2, 6, 3] + growTime: [4, 10, 1, 9, 2, 8] + out: 28 + - name: "six_mixed_b" + in: + plantTime: [1, 8, 2, 7, 3, 6] + growTime: [10, 4, 9, 1, 8, 2] + out: 28 + - name: "generated_small" + seed: 11 + in: + plantTime: + gen: "array" + len: 7 + of: + gen: "int" + min: 1 + max: 20 + growTime: + gen: "array" + len: 7 + of: + gen: "int" + min: 1 + max: 20 + - name: "generated_medium" + seed: 22 + in: + plantTime: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 10000 + growTime: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 10000 + - name: "generated_boundary" + seed: 33 + in: + plantTime: + gen: "array" + len: 20 + of: + gen: "int" + min: 1 + max: 10000 + growTime: + gen: "array" + len: 20 + of: + gen: "int" + min: 1 + max: 10000 + - name: "stress_max_a" + seed: 44 + in: + plantTime: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 10000 + growTime: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 10000 + - name: "stress_max_b" + seed: 55 + in: + plantTime: + gen: "array" + len: 99999 + of: + gen: "int" + min: 1 + max: 10000 + growTime: + gen: "array" + len: 99999 + of: + gen: "int" + min: 1 + max: 10000 diff --git a/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/sol.py b/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/sol.py new file mode 100644 index 00000000..de23e88e --- /dev/null +++ b/tests/2001-2500/2136. earliest-possible-day-of-full-bloom/sol.py @@ -0,0 +1,6 @@ +class Solution: + def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: + return reduce( + lambda res, gp: max(res, gp[0]) + gp[1], + sorted(zip(growTime, plantTime)), + 0) \ No newline at end of file diff --git a/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/manifest.yaml b/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/manifest.yaml new file mode 100644 index 00000000..94a87c00 --- /dev/null +++ b/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/manifest.yaml @@ -0,0 +1,333 @@ +entry: + id: 2138 + title: "divide-a-string-into-groups-of-size-k" + params: + s: + type: string + k: + type: int + fill: + type: char + call: + cpp: "Solution().divideString({s}, {k}, {fill})" + rust: "Solution::divide_string({s}, {k}, {fill})" + python3: "Solution().divideString({s}, {k}, {fill})" + python2: "Solution().divideString({s}, {k}, {fill})" + ruby: "divide_string({s}, {k}, {fill})" + java: "new Solution().divideString({s}, {k}, {fill})" + csharp: "new Solution().DivideString({s}, {k}, {fill})" + kotlin: "Solution().divideString({s}, {k}, {fill})" + go: "divideString({s}, {k}, {fill})" + dart: "Solution().divideString({s}, {k}, {fill})" + swift: "Solution().divideString({s}, {k}, {fill})" + typescript: "divideString({s}, {k}, {fill})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().divideString(s, k, fill, {result})" + checker: | + class Checker: + def divideString(self, s, k, fill, result): + if not isinstance(result, list) or not result: + return False + expected_count = (len(s) + k - 1) // k + if len(result) != expected_count: + return False + for i, group in enumerate(result): + if not isinstance(group, str) or len(group) != k: + return False + start = i * k + expected = s[start:start + k] + if len(expected) < k: + expected += fill * (k - len(expected)) + if group != expected: + return False + return ''.join(result)[:len(s)] == s + +seed: 2138 + +tests: + - name: "example_exact_division" + in: + s: "abcdefghi" + k: 3 + fill: "x" + out: ["abc", "def", "ghi"] + - name: "example_padded_tail" + in: + s: "abcdefghij" + k: 3 + fill: "x" + out: ["abc", "def", "ghi", "jxx"] + - name: "single_character" + in: + s: "a" + k: 1 + fill: "z" + out: ["a"] + - name: "single_character_large_group" + in: + s: "q" + k: 100 + fill: "m" + out: ["qmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"] + - name: "k_one" + in: + s: "leetcode" + k: 1 + fill: "x" + out: ["l", "e", "e", "t", "c", "o", "d", "e"] + - name: "k_equals_length" + in: + s: "openleetcode" + k: 12 + fill: "a" + out: ["openleetcode"] + - name: "k_greater_than_length" + in: + s: "abcde" + k: 7 + fill: "z" + out: ["abcdezz"] + - name: "repeated_letters_exact" + in: + s: "aaaaaaaaaa" + k: 5 + fill: "b" + out: ["aaaaa", "aaaaa"] + - name: "repeated_letters_padded" + in: + s: "zzzzz" + k: 2 + fill: "z" + out: ["zz", "zz", "zz"] + - name: "fill_same_as_tail" + in: + s: "helloworld" + k: 4 + fill: "o" + out: ["hell", "owor", "ldoo"] + - name: "remainder_one" + in: + s: "abcdefghijk" + k: 5 + fill: "p" + out: ["abcde", "fghij", "kpppp"] + - name: "remainder_k_minus_one" + in: + s: "abcdefghijkl" + k: 4 + fill: "w" + out: ["abcd", "efgh", "ijkl"] + - name: "two_groups_one_short" + in: + s: "abcdefg" + k: 4 + fill: "r" + out: ["abcd", "efgr"] + - name: "alternating_letters" + in: + s: "ababababab" + k: 3 + fill: "c" + out: ["aba", "bab", "aba", "bcc"] + - name: "alphabet_prefix" + in: + s: "abcdefghijklmnopqrstuvwxyz" + k: 10 + fill: "q" + out: ["abcdefghij", "klmnopqrst", "uvwxyzqqqq"] + - name: "large_k_two" + in: + s: "abcdefghij" + k: 2 + fill: "v" + out: ["ab", "cd", "ef", "gh", "ij"] + - name: "length_ninety_nine_k_ten" + in: + s: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + k: 10 + fill: "b" + out: + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaaa" + - "aaaaaaaaab" + - name: "length_hundred_k_hundred" + in: + s: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" + k: 100 + fill: "x" + out: + - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" + - name: "two_characters_k_one" + in: + s: "xy" + k: 1 + fill: "a" + out: ["x", "y"] + - name: "two_characters_k_two" + in: + s: "xy" + k: 2 + fill: "a" + out: ["xy"] + - name: "two_characters_k_three" + in: + s: "xy" + k: 3 + fill: "a" + out: ["xya"] + - name: "length_three_k_two" + in: + s: "cat" + k: 2 + fill: "d" + out: ["ca", "td"] + - name: "length_four_k_three" + in: + s: "bird" + k: 3 + fill: "x" + out: ["bir", "dxx"] + - name: "length_five_k_four" + in: + s: "apple" + k: 4 + fill: "z" + out: ["appl", "ezzz"] + - name: "length_six_k_four" + in: + s: "orange" + k: 4 + fill: "q" + out: ["oran", "geqq"] + - name: "length_seven_k_three" + in: + s: "network" + k: 3 + fill: "s" + out: ["net", "wor", "kss"] + - name: "length_eight_k_five" + in: + s: "computer" + k: 5 + fill: "x" + out: ["compu", "terxx"] + - name: "length_twelve_k_five" + in: + s: "abcdefghijkl" + k: 5 + fill: "z" + out: ["abcde", "fghij", "klzzz"] + - name: "length_thirteen_k_six" + in: + s: "abcdefghijklm" + k: 6 + fill: "n" + out: ["abcdef", "ghijkl", "mnnnnn"] + - name: "length_twenty_k_seven" + in: + s: "abcdefghijklmnopqrst" + k: 7 + fill: "x" + out: ["abcdefg", "hijklmn", "opqrstx"] + - name: "fill_is_a" + in: + s: "coding" + k: 4 + fill: "a" + out: ["codi", "ngaa"] + - name: "fill_is_z" + in: + s: "testing" + k: 5 + fill: "z" + out: ["testi", "ngzzz"] + - name: "generated_short_mixed" + seed: 101 + in: + s: + gen: "str" + len: + gen: "int" + min: 1 + max: 20 + alphabet: "abcx" + k: + gen: "int" + min: 1 + max: 20 + fill: + gen: "char" + variety: ["d", "e", "f"] + - name: "generated_medium" + seed: 202 + in: + s: + gen: "str" + len: + gen: "int" + min: 21 + max: 60 + alphabet: "amz" + k: + gen: "int" + min: 2 + max: 30 + fill: + gen: "char" + variety: ["a", "q", "z"] + - name: "generated_maximum_length" + seed: 303 + in: + s: + gen: "str" + len: 100 + alphabet: "abcdefghijklm" + k: + gen: "int" + min: 1 + max: 100 + fill: + gen: "char" + variety: ["n", "o", "p"] + - name: "generated_large_groups" + seed: 404 + in: + s: + gen: "str" + len: + gen: "int" + min: 80 + max: 100 + alphabet: "rstu" + k: + gen: "int" + min: 50 + max: 100 + fill: + gen: "char" + variety: ["v", "w", "x"] + - name: "generated_k_one" + seed: 505 + in: + s: + gen: "str" + len: 100 + alphabet: "qr" + k: 1 + fill: "z" diff --git a/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/sol.py b/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/sol.py new file mode 100644 index 00000000..94577da8 --- /dev/null +++ b/tests/2001-2500/2138. divide-a-string-into-groups-of-size-k/sol.py @@ -0,0 +1,17 @@ +class Solution: + def divideString(self, s: str, k: int, fill: str) -> list[str]: + n = len(s) + groups = (n + k - 1) // k + result = [] + + for i in range(groups): + group = '' + for j in range(k): + index = i * k + j + if index < n: + group += s[index] + else: + group += fill # Padding + result.append(group) + + return result \ No newline at end of file diff --git a/tests/2001-2500/2139. minimum-moves-to-reach-target-score/manifest.yaml b/tests/2001-2500/2139. minimum-moves-to-reach-target-score/manifest.yaml new file mode 100644 index 00000000..dac60706 --- /dev/null +++ b/tests/2001-2500/2139. minimum-moves-to-reach-target-score/manifest.yaml @@ -0,0 +1,276 @@ +entry: + id: 2139 + title: "minimum-moves-to-reach-target-score" + params: + target: + type: int + maxDoubles: + type: int + call: + cpp: "Solution().minMoves({target}, {maxDoubles})" + rust: "Solution::min_moves({target}, {maxDoubles})" + python3: "Solution().minMoves({target}, {maxDoubles})" + python2: "Solution().minMoves({target}, {maxDoubles})" + ruby: "min_moves({target}, {maxDoubles})" + java: "new Solution().minMoves({target}, {maxDoubles})" + csharp: "new Solution().MinMoves({target}, {maxDoubles})" + kotlin: "Solution().minMoves({target}, {maxDoubles})" + go: "minMoves({target}, {maxDoubles})" + dart: "Solution().minMoves({target}, {maxDoubles})" + swift: "Solution().minMoves({target}, {maxDoubles})" + typescript: "minMoves({target}, {maxDoubles})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minMoves(target, maxDoubles, {result})" + checker: | + class Checker: + def minMoves(self, target, maxDoubles, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + moves = 0 + while target > 1 and maxDoubles > 0: + if target & 1: + target -= 1 + else: + target //= 2 + maxDoubles -= 1 + moves += 1 + expected = moves + max(0, target - 1) + return result == expected + +seed: 2139 + +tests: + - name: "minimum_target" + in: + target: 1 + maxDoubles: 0 + out: 0 + - name: "target_two_no_doubles" + in: + target: 2 + maxDoubles: 0 + out: 1 + - name: "example_one" + in: + target: 5 + maxDoubles: 0 + out: 4 + - name: "example_two" + in: + target: 19 + maxDoubles: 2 + out: 7 + - name: "example_three" + in: + target: 10 + maxDoubles: 4 + out: 4 + - name: "doubles_unused_at_one" + in: + target: 1 + maxDoubles: 100 + out: 0 + - name: "no_doubles_small_odd" + in: + target: 17 + maxDoubles: 0 + out: 16 + - name: "no_doubles_max_target" + in: + target: 1000000000 + maxDoubles: 0 + out: 999999999 + - name: "one_double_even" + in: + target: 4 + maxDoubles: 1 + out: 2 + - name: "one_double_odd" + in: + target: 7 + maxDoubles: 1 + out: 4 + - name: "one_double_power" + in: + target: 8 + maxDoubles: 1 + out: 4 + - name: "one_double_large" + in: + target: 100 + maxDoubles: 1 + out: 50 + - name: "odd_requires_increment" + in: + target: 3 + maxDoubles: 1 + out: 2 + - name: "odd_chain" + in: + target: 15 + maxDoubles: 2 + out: 6 + - name: "even_chain" + in: + target: 16 + maxDoubles: 2 + out: 5 + - name: "exact_power_two" + in: + target: 32 + maxDoubles: 5 + out: 5 + - name: "more_doubles_than_needed" + in: + target: 32 + maxDoubles: 100 + out: 5 + - name: "power_two_limited" + in: + target: 64 + maxDoubles: 2 + out: 17 + - name: "near_power_low" + in: + target: 31 + maxDoubles: 4 + out: 8 + - name: "near_power_high" + in: + target: 33 + maxDoubles: 4 + out: 6 + - name: "target_50_doubles_3" + in: + target: 50 + maxDoubles: 3 + out: 9 + - name: "target_99_doubles_2" + in: + target: 99 + maxDoubles: 2 + out: 27 + - name: "target_127_doubles_6" + in: + target: 127 + maxDoubles: 6 + out: 12 + - name: "target_128_doubles_6" + in: + target: 128 + maxDoubles: 6 + out: 7 + - name: "target_129_doubles_6" + in: + target: 129 + maxDoubles: 6 + out: 8 + - name: "target_255_doubles_7" + in: + target: 255 + maxDoubles: 7 + out: 14 + - name: "target_256_doubles_7" + in: + target: 256 + maxDoubles: 7 + out: 8 + - name: "target_257_doubles_7" + in: + target: 257 + maxDoubles: 7 + out: 9 + - name: "target_1000_doubles_3" + in: + target: 1000 + maxDoubles: 3 + out: 127 + - name: "target_1000_doubles_10" + in: + target: 1000 + maxDoubles: 10 + out: 14 + - name: "target_999999937_doubles_1" + in: + target: 999999937 + maxDoubles: 1 + out: 499999969 + - name: "target_999999999_doubles_100" + in: + target: 999999999 + maxDoubles: 100 + out: 49 + - name: "large_even_many_doubles" + in: + target: 1000000000 + maxDoubles: 100 + out: 41 + - name: "large_odd_many_doubles" + in: + target: 999999999 + maxDoubles: 99 + out: 49 + - name: "generated_small_mixed" + seed: 101 + in: + target: + gen: "int" + min: 1 + max: 1000 + maxDoubles: + gen: "int" + min: 0 + max: 100 + - name: "generated_medium" + seed: 202 + in: + target: + gen: "int" + min: 1001 + max: 1000000 + maxDoubles: + gen: "int" + min: 0 + max: 100 + - name: "generated_low_doubles" + seed: 303 + in: + target: + gen: "int" + min: 1000000 + max: 100000000 + maxDoubles: + gen: "int" + min: 0 + max: 3 + - name: "generated_near_maximum" + seed: 404 + in: + target: + gen: "int" + min: 900000000 + max: 1000000000 + maxDoubles: + gen: "int" + min: 50 + max: 100 + - name: "generated_maximum_scale" + seed: 505 + in: + target: + gen: "int" + min: 999000000 + max: 1000000000 + maxDoubles: + gen: "int" + min: 90 + max: 100 diff --git a/tests/2001-2500/2139. minimum-moves-to-reach-target-score/sol.py b/tests/2001-2500/2139. minimum-moves-to-reach-target-score/sol.py new file mode 100644 index 00000000..e9786d4a --- /dev/null +++ b/tests/2001-2500/2139. minimum-moves-to-reach-target-score/sol.py @@ -0,0 +1,17 @@ +class Solution: + def minMoves(self, target: int, maxDoubles: int) -> int: + steps = 0 + + while target > 1 and maxDoubles > 0: + if target % 2 == 0: + target //= 2 + maxDoubles -= 1 + else: + target -= 1 + steps += 1 + + # Add remaining steps if target > 1 + if target > 1: + steps += (target - 1) + + return steps \ No newline at end of file diff --git a/tests/2001-2500/2140. solving-questions-with-brainpower/manifest.yaml b/tests/2001-2500/2140. solving-questions-with-brainpower/manifest.yaml new file mode 100644 index 00000000..cc821f04 --- /dev/null +++ b/tests/2001-2500/2140. solving-questions-with-brainpower/manifest.yaml @@ -0,0 +1,417 @@ +entry: + id: 2140 + title: "solving-questions-with-brainpower" + params: + questions: + type: array + items: + type: array + items: + type: int + call: + cpp: "Solution().mostPoints({questions})" + rust: "Solution::most_points({questions})" + python3: "Solution().mostPoints({questions})" + python2: "Solution().mostPoints({questions})" + ruby: "most_points({questions})" + java: "new Solution().mostPoints({questions})" + csharp: "new Solution().MostPoints({questions})" + kotlin: "Solution().mostPoints({questions})" + go: "mostPoints({questions})" + dart: "Solution().mostPoints({questions})" + swift: "Solution().mostPoints({questions})" + typescript: "mostPoints({questions})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().mostPoints(questions, {result})" + checker: | + class Checker: + def mostPoints(self, questions, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + n = len(questions) + dp = [0] * (n + 1) + for i in range(n - 1, -1, -1): + points, brainpower = questions[i] + nxt = i + brainpower + 1 + take = points + (dp[nxt] if nxt < n else 0) + dp[i] = max(dp[i + 1], take) + return result == dp[0] + +seed: 2140 + +tests: + - name: "example_one" + in: + questions: + - [3, 2] + - [4, 3] + - [4, 4] + - [2, 5] + out: 5 + - name: "example_two" + in: + questions: + - [1, 1] + - [2, 2] + - [3, 3] + - [4, 4] + - [5, 5] + out: 7 + - name: "single_question" + in: + questions: + - [1, 1] + out: 1 + - name: "single_max_values" + in: + questions: + - [100000, 100000] + out: 100000 + - name: "all_questions_skippable_after_first" + in: + questions: + - [10, 100000] + - [9, 1] + - [8, 1] + - [7, 1] + out: 16 + - name: "all_brainpower_one" + in: + questions: + - [5, 1] + - [1, 1] + - [5, 1] + - [1, 1] + - [5, 1] + out: 15 + - name: "all_brainpower_zero_like_boundary" + in: + questions: + - [2, 1] + - [3, 1] + - [4, 1] + - [5, 1] + - [6, 1] + - [7, 1] + out: 15 + - name: "take_every_other" + in: + questions: + - [10, 1] + - [1, 1] + - [10, 1] + - [1, 1] + - [10, 1] + - [1, 1] + out: 30 + - name: "skip_to_larger_later_value" + in: + questions: + - [1, 1] + - [100, 1] + - [1, 1] + - [1, 1] + out: 101 + - name: "long_jump_vs_two_rewards" + in: + questions: + - [10, 2] + - [20, 1] + - [30, 1] + - [40, 1] + out: 60 + - name: "jump_exactly_to_last" + in: + questions: + - [8, 3] + - [1, 1] + - [1, 1] + - [1, 1] + - [9, 1] + out: 17 + - name: "jump_past_end" + in: + questions: + - [4, 2] + - [100, 100000] + - [3, 1] + out: 100 + - name: "repeated_equal_pairs" + in: + questions: + - [7, 2] + - [7, 2] + - [7, 2] + - [7, 2] + - [7, 2] + - [7, 2] + out: 14 + - name: "alternating_long_jumps" + in: + questions: + - [9, 4] + - [50, 1] + - [8, 4] + - [50, 1] + - [7, 4] + - [50, 1] + - [6, 4] + out: 150 + - name: "large_points_small_brainpower" + in: + questions: + - [100000, 1] + - [99999, 1] + - [100000, 1] + - [99999, 1] + - [100000, 1] + out: 300000 + - name: "mixed_dense_choices" + in: + questions: + - [3, 1] + - [8, 2] + - [2, 1] + - [9, 1] + - [4, 3] + - [10, 1] + - [1, 1] + - [7, 2] + out: 29 + - name: "increasing_points_increasing_brainpower" + in: + questions: + - [1, 1] + - [2, 2] + - [3, 3] + - [4, 4] + - [5, 5] + - [6, 6] + - [7, 7] + - [8, 8] + out: 12 + - name: "decreasing_points_increasing_brainpower" + in: + questions: + - [20, 1] + - [19, 2] + - [18, 3] + - [17, 4] + - [16, 5] + - [15, 6] + out: 38 + - name: "short_chain" + in: + questions: + - [5, 1] + - [4, 1] + - [3, 1] + out: 8 + - name: "best_is_last" + in: + questions: + - [1, 100] + - [1, 100] + - [1, 100] + - [100000, 1] + out: 100000 + - name: "best_is_first" + in: + questions: + - [100000, 100000] + - [1, 1] + - [1, 1] + - [1, 1] + out: 100000 + - name: "multiple_zero_effect_choices" + in: + questions: + - [6, 1] + - [6, 1] + - [6, 1] + - [6, 1] + - [6, 1] + - [6, 1] + - [6, 1] + out: 24 + - name: "large_jump_middle" + in: + questions: + - [2, 1] + - [3, 1] + - [100, 3] + - [4, 1] + - [5, 1] + - [6, 1] + - [7, 1] + out: 109 + - name: "one_step_decision_chain" + in: + questions: + - [4, 1] + - [10, 1] + - [4, 1] + - [10, 1] + - [4, 1] + - [10, 1] + - [4, 1] + - [10, 1] + out: 40 + - name: "all_max_points_short_jumps" + in: + questions: + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + out: 300000 + - name: "varied_small_values" + in: + questions: + - [1, 1] + - [2, 3] + - [3, 1] + - [1, 2] + - [4, 1] + - [2, 2] + - [5, 1] + - [3, 3] + - [6, 1] + out: 19 + - name: "near_integer_answer_limit" + in: + questions: + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + - [100000, 1] + out: 500000 + - name: "late_competition" + in: + questions: + - [5, 5] + - [4, 1] + - [4, 1] + - [4, 1] + - [4, 1] + - [20, 1] + - [1, 1] + out: 28 + - name: "alternating_brainpower" + in: + questions: + - [12, 1] + - [1, 5] + - [12, 1] + - [1, 5] + - [12, 1] + - [1, 5] + - [12, 1] + out: 48 + - name: "generated_small" + seed: 101 + in: + questions: + gen: "array" + len: + gen: "int" + min: 1 + max: 25 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 100000 + - name: "generated_medium" + seed: 202 + in: + questions: + gen: "array" + len: + gen: "int" + min: 100 + max: 300 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 100000 + - name: "generated_max_points" + seed: 303 + in: + questions: + gen: "array" + len: + gen: "int" + min: 1000 + max: 1500 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 100000 + max: 100000 + - name: "generated_max_brainpower" + seed: 404 + in: + questions: + gen: "array" + len: + gen: "int" + min: 1000 + max: 1500 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 100000 + - name: "stress_fifty_thousand" + seed: 505 + in: + questions: + gen: "array" + len: 50000 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 100000 + - name: "stress_one_hundred_thousand" + seed: 606 + in: + questions: + gen: "array" + len: 100000 + of: + gen: "array" + len: 2 + of: + gen: "int" + min: 1 + max: 100000 diff --git a/tests/2001-2500/2140. solving-questions-with-brainpower/sol.py b/tests/2001-2500/2140. solving-questions-with-brainpower/sol.py new file mode 100644 index 00000000..319b5132 --- /dev/null +++ b/tests/2001-2500/2140. solving-questions-with-brainpower/sol.py @@ -0,0 +1,12 @@ +class Solution(object): + def mostPoints(self, questions): + dp = [0] * len(questions) + for i in range(len(questions) - 1, -1, -1): + index = i + questions[i][1] + 1 + if index < len(questions): + dp[i] = dp[index] + questions[i][0] + else: + dp[i] = questions[i][0] + if i < len(questions) - 1: + dp[i] = max(dp[i + 1], dp[i]) + return dp[0] \ No newline at end of file diff --git a/tests/2001-2500/2141. maximum-running-time-of-n-computers/manifest.yaml b/tests/2001-2500/2141. maximum-running-time-of-n-computers/manifest.yaml new file mode 100644 index 00000000..f5626569 --- /dev/null +++ b/tests/2001-2500/2141. maximum-running-time-of-n-computers/manifest.yaml @@ -0,0 +1,290 @@ +entry: + id: 2141 + title: "maximum-running-time-of-n-computers" + params: + n: + type: int + batteries: + type: array + items: + type: int + call: + cpp: "Solution().maxRunTime({n}, {batteries})" + rust: "Solution::max_run_time({n}, {batteries})" + python3: "Solution().maxRunTime({n}, {batteries})" + python2: "Solution().maxRunTime({n}, {batteries})" + ruby: "max_run_time({n}, {batteries})" + java: "new Solution().maxRunTime({n}, {batteries})" + csharp: "new Solution().MaxRunTime({n}, {batteries})" + kotlin: "Solution().maxRunTime({n}, {batteries})" + go: "maxRunTime({n}, {batteries})" + dart: "Solution().maxRunTime({n}, {batteries})" + swift: "Solution().maxRunTime({n}, {batteries})" + typescript: "maxRunTime({n}, {batteries})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 512 + +oracle: + python3: + call: "Checker().maxRunTime(n, batteries, {result})" + checker: | + class Checker: + def maxRunTime(self, n, batteries, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + if n < 1 or len(batteries) < n or any(x < 1 for x in batteries): + return False + total = sum(batteries) + lo, hi = 0, total // n + while lo < hi: + mid = (lo + hi + 1) // 2 + usable = sum(x if x < mid else mid for x in batteries) + if usable // n >= mid: + lo = mid + else: + hi = mid - 1 + return result == lo + +seed: 2141001 + +tests: + - name: "example_one" + in: + n: 2 + batteries: [3, 3, 3] + out: 4 + - name: "example_two" + in: + n: 2 + batteries: [1, 1, 1, 1] + out: 2 + - name: "single_computer_one_battery" + in: + n: 1 + batteries: [1] + out: 1 + - name: "single_computer_many_batteries" + in: + n: 1 + batteries: [5, 2, 9, 1] + out: 17 + - name: "all_computers_equal" + in: + n: 4 + batteries: [7, 7, 7, 7] + out: 7 + - name: "all_computers_unequal" + in: + n: 4 + batteries: [1, 2, 3, 4] + out: 1 + - name: "one_dominant_battery" + in: + n: 3 + batteries: [100, 1, 1] + out: 1 + - name: "dominant_battery_with_reserve" + in: + n: 2 + batteries: [100, 1, 1] + out: 2 + - name: "many_small_batteries" + in: + n: 5 + batteries: [1, 1, 1, 1, 1, 1, 1, 1] + out: 1 + - name: "exact_total_division" + in: + n: 3 + batteries: [2, 4, 6] + out: 2 + - name: "remainder_total" + in: + n: 3 + batteries: [2, 4, 7] + out: 2 + - name: "cap_is_binding" + in: + n: 2 + batteries: [8, 8, 1] + out: 8 + - name: "cap_is_not_binding" + in: + n: 3 + batteries: [2, 3, 4, 5] + out: 4 + - name: "minimum_battery_limits_answer" + in: + n: 3 + batteries: [1, 50, 50] + out: 1 + - name: "zero_not_allowed_boundary_one" + in: + n: 2 + batteries: [1, 2] + out: 1 + - name: "large_int_values" + in: + n: 2 + batteries: [1000000000, 1000000000] + out: 1000000000 + - name: "large_int_sum_over_32_bit" + in: + n: 3 + batteries: [1000000000, 1000000000, 1000000000, 1000000000] + out: 1333333333 + - name: "large_imbalance" + in: + n: 5 + batteries: [1000000000, 1, 1, 1, 1, 1] + out: 1 + - name: "two_computers_pairing" + in: + n: 2 + batteries: [4, 5, 6, 7] + out: 11 + - name: "three_computers_pairing" + in: + n: 3 + batteries: [5, 5, 5, 5] + out: 6 + - name: "duplicate_short_batteries" + in: + n: 3 + batteries: [2, 2, 2, 10, 10] + out: 6 + - name: "sorted_ascending" + in: + n: 4 + batteries: [1, 3, 5, 7, 9] + out: 4 + - name: "sorted_descending" + in: + n: 4 + batteries: [9, 7, 5, 3, 1] + out: 4 + - name: "extra_batteries_all_useful" + in: + n: 2 + batteries: [2, 2, 2, 2, 2] + out: 5 + - name: "extra_batteries_partly_capped" + in: + n: 2 + batteries: [1, 1, 1, 10] + out: 3 + - name: "n_equals_length_mixed" + in: + n: 6 + batteries: [6, 1, 4, 2, 8, 3] + out: 1 + - name: "n_equals_length_equal" + in: + n: 8 + batteries: [12, 12, 12, 12, 12, 12, 12, 12] + out: 12 + - name: "near_capacity_two" + in: + n: 2 + batteries: [1, 3, 3, 3] + out: 5 + - name: "near_capacity_four" + in: + n: 4 + batteries: [2, 2, 2, 2, 2, 2, 2] + out: 3 + - name: "generated_small_balanced" + seed: 214101 + in: + n: 2 + batteries: + gen: "array" + len: + gen: "int" + min: 2 + max: 12 + of: + gen: "int" + min: 1 + max: 30 + + - name: "generated_medium_three" + seed: 214102 + in: + n: 3 + batteries: + gen: "array" + len: + gen: "int" + min: 3 + max: 40 + of: + gen: "int" + min: 1 + max: 1000 + - name: "generated_many_computers" + seed: 214103 + in: + n: 25 + batteries: + gen: "array" + len: + gen: "int" + min: 25 + max: 100 + of: + gen: "int" + min: 1 + max: 100000 + - name: "generated_large_values" + seed: 214104 + in: + n: 10 + batteries: + gen: "array" + len: + gen: "int" + min: 10 + max: 80 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_stress_100k" + seed: 214105 + in: + n: 50000 + batteries: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_stress_minimum_n" + seed: 214106 + in: + n: 1 + batteries: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 1000000000 + - name: "generated_stress_all_computers" + seed: 214107 + in: + n: 100000 + batteries: + gen: "array" + len: 100000 + of: + gen: "int" + min: 1 + max: 1000000000 diff --git a/tests/2001-2500/2141. maximum-running-time-of-n-computers/sol.py b/tests/2001-2500/2141. maximum-running-time-of-n-computers/sol.py new file mode 100644 index 00000000..573dfbef --- /dev/null +++ b/tests/2001-2500/2141. maximum-running-time-of-n-computers/sol.py @@ -0,0 +1,13 @@ +class Solution: + def maxRunTime(self, n: int, batteries: List[int]) -> int: + l, r, ans=min(batteries), sum(batteries)//n, 0 + while l<=r: + mid=(l+r)>>1 + reserve=0 + for x in batteries: reserve+=min(x, mid) + if reserve>=mid*n: + ans=mid + l=mid+1 + else: + r=mid-1 + return ans \ No newline at end of file diff --git a/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/manifest.yaml b/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/manifest.yaml new file mode 100644 index 00000000..29228cb3 --- /dev/null +++ b/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/manifest.yaml @@ -0,0 +1,207 @@ +entry: + id: 2144 + title: "minimum-cost-of-buying-candies-with-discount" + params: + cost: + type: array + items: + type: int + call: + cpp: "Solution().minimumCost({cost})" + rust: "Solution::minimum_cost({cost})" + python3: "Solution().minimumCost({cost})" + python2: "Solution().minimumCost({cost})" + ruby: "minimum_cost({cost})" + java: "new Solution().minimumCost({cost})" + csharp: "new Solution().MinimumCost({cost})" + kotlin: "Solution().minimumCost({cost})" + go: "minimumCost({cost})" + dart: "Solution().minimumCost({cost})" + swift: "Solution().minimumCost({cost})" + typescript: "minimumCost({cost})" + +judge: + type: "exact" + +limits: + time_ms: 200 + memory_mb: 300 + +oracle: + python3: + call: "Checker().minimumCost(cost, {result})" + checker: | + class Checker: + def minimumCost(self, cost, result): + if not isinstance(cost, list) or not 1 <= len(cost) <= 100: + return False + if any(isinstance(x, bool) or not isinstance(x, int) or not 1 <= x <= 100 for x in cost): + return False + if isinstance(result, bool) or not isinstance(result, int): + return False + ordered = sorted(cost, reverse=True) + expected = sum(x for i, x in enumerate(ordered) if i % 3 != 2) + return result == expected + +seed: 2144 + +tests: + - name: "example_1" + in: + cost: [1, 2, 3] + out: 5 + - name: "example_2" + in: + cost: [6, 5, 7, 9, 2, 2] + out: 23 + - name: "example_3" + in: + cost: [5, 5] + out: 10 + - name: "single_min" + in: + cost: [1] + - name: "single_max" + in: + cost: [100] + - name: "two_different" + in: + cost: [1, 100] + - name: "three_equal" + in: + cost: [7, 7, 7] + - name: "four_equal" + in: + cost: [9, 9, 9, 9] + - name: "five_equal" + in: + cost: [4, 4, 4, 4, 4] + - name: "six_equal" + in: + cost: [100, 100, 100, 100, 100, 100] + - name: "three_ordered" + in: + cost: [1, 2, 100] + - name: "three_reverse" + in: + cost: [100, 2, 1] + - name: "four_low_free" + in: + cost: [1, 2, 3, 100] + - name: "four_high_free_unavailable" + in: + cost: [100, 99, 98, 1] + - name: "five_mixed" + in: + cost: [10, 1, 8, 3, 6] + - name: "six_duplicates" + in: + cost: [2, 2, 2, 3, 3, 3] + - name: "seven_boundary" + in: + cost: [1, 2, 3, 4, 5, 6, 7] + - name: "eight_boundary" + in: + cost: [100, 1, 99, 2, 98, 3, 97, 4] + - name: "nine_groups" + in: + cost: [11, 12, 13, 14, 15, 16, 17, 18, 19] + - name: "ten_repeated_extremes" + in: + cost: [1, 100, 1, 100, 1, 100, 1, 100, 1, 100] + - name: "eleven_unsorted" + in: + cost: [42, 7, 99, 13, 13, 1, 88, 2, 76, 35, 4] + - name: "twelve_all_min" + in: + cost: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + - name: "thirteen_all_max" + in: + cost: [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100] + - name: "fourteen_linear" + in: + cost: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + - name: "fifteen_randomish" + in: + cost: [73, 5, 61, 44, 92, 18, 18, 37, 2, 86, 50, 8, 67, 31, 99] + - name: "sixteen_two_values" + in: + cost: [2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100] + - name: "twenty_prime_pattern" + in: + cost: [97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13] + - name: "twentyfive_cycle" + in: + cost: [1, 50, 2, 49, 3, 48, 4, 47, 5, 46, 6, 45, 7, 44, 8, 43, 9, 42, 10, 41, 11, 40, 12, 39, 13] + - name: "thirty_mixed" + in: + cost: [100, 1, 50, 2, 75, 3, 25, 4, 60, 5, 90, 6, 30, 7, 80, 8, 40, 9, 70, 10, 20, 11, 65, 12, 55, 13, 35, 14, 85, 15] + - name: "fifty_all_min" + in: + cost: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + - name: "generated_small" + seed: 3001 + in: + cost: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + - name: "generated_medium" + seed: 3002 + in: + cost: + gen: "array" + len: + gen: "int" + min: 21 + max: 60 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + - name: "generated_max" + seed: 3003 + in: + cost: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100 + distinct: false + sorted: false + - name: "generated_max_low_values" + seed: 3004 + in: + cost: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 3 + distinct: false + sorted: false + - name: "generated_max_high_values" + seed: 3005 + in: + cost: + gen: "array" + len: 95 + of: + gen: "int" + min: 98 + max: 100 + distinct: false + sorted: false diff --git a/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/sol.py b/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/sol.py new file mode 100644 index 00000000..21f06da1 --- /dev/null +++ b/tests/2001-2500/2144. minimum-cost-of-buying-candies-with-discount/sol.py @@ -0,0 +1,26 @@ +class Solution: + def minimumCost(self, cost: List[int]) -> int: + total_cost = 0 + cost.sort(reverse=True) + + l = len(cost) + + num_three = l // 3 + mod_three = l % 3 + + pos = 0 + for i in range(0, num_three): + first_candy = cost[pos] + total_cost = total_cost + first_candy + pos+=1 + second_candy = cost[pos] + total_cost = total_cost + second_candy + pos+=2 + # third candy is free + + for i in range(0, mod_three): + candy = cost[pos] + total_cost = total_cost + candy + pos+=1 + + return total_cost \ No newline at end of file diff --git a/tests/2001-2500/2145. count-the-hidden-sequences/manifest.yaml b/tests/2001-2500/2145. count-the-hidden-sequences/manifest.yaml new file mode 100644 index 00000000..c8a21c0c --- /dev/null +++ b/tests/2001-2500/2145. count-the-hidden-sequences/manifest.yaml @@ -0,0 +1,324 @@ +entry: + id: 2145 + title: "count-the-hidden-sequences" + params: + differences: + type: array + items: + type: int + lower: + type: int + upper: + type: int + call: + cpp: "Solution().numberOfArrays({differences}, {lower}, {upper})" + rust: "Solution::number_of_arrays({differences}, {lower}, {upper})" + python3: "Solution().numberOfArrays({differences}, {lower}, {upper})" + python2: "Solution().numberOfArrays({differences}, {lower}, {upper})" + ruby: "number_of_arrays({differences}, {lower}, {upper})" + java: "new Solution().numberOfArrays({differences}, {lower}, {upper})" + csharp: "new Solution().NumberOfArrays({differences}, {lower}, {upper})" + kotlin: "Solution().numberOfArrays({differences}, {lower}, {upper})" + go: "numberOfArrays({differences}, {lower}, {upper})" + dart: "Solution().numberOfArrays({differences}, {lower}, {upper})" + swift: "Solution().numberOfArrays({differences}, {lower}, {upper})" + typescript: "numberOfArrays({differences}, {lower}, {upper})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().numberOfArrays(differences, lower, upper, {result})" + checker: | + class Checker: + def numberOfArrays(self, differences, lower, upper, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + lo = hi = 0 + current = 0 + for delta in differences: + current += delta + lo = min(lo, current) + hi = max(hi, current) + expected = max(0, (upper - lower + 1) - (hi - lo)) + return result == expected + +seed: 2145 + +tests: + - name: "example_1" + in: + differences: [1, -3, 4] + lower: 1 + upper: 6 + out: 2 + - name: "example_2" + in: + differences: [3, -4, 5, 1, -2] + lower: -4 + upper: 5 + out: 4 + - name: "example_3_no_sequence" + in: + differences: [4, -7, 2] + lower: 3 + upper: 6 + out: 0 + - name: "single_zero_full_range" + in: + differences: [0] + lower: -100000 + upper: 100000 + out: 200001 + - name: "single_positive_exact_span" + in: + differences: [5] + lower: 0 + upper: 5 + out: 1 + - name: "single_positive_too_narrow" + in: + differences: [5] + lower: 0 + upper: 4 + out: 0 + - name: "single_negative_exact_span" + in: + differences: [-5] + lower: -5 + upper: 0 + out: 1 + - name: "all_positive" + in: + differences: [1, 2, 3, 4] + lower: -10 + upper: 10 + out: 11 + - name: "all_negative" + in: + differences: [-1, -2, -3, -4] + lower: -10 + upper: 10 + out: 11 + - name: "return_to_origin" + in: + differences: [5, -5] + lower: 7 + upper: 7 + out: 0 + - name: "return_to_origin_wide" + in: + differences: [5, -5] + lower: -2 + upper: 10 + out: 8 + - name: "large_positive_jump" + in: + differences: [100000] + lower: -100000 + upper: 100000 + out: 100001 + - name: "large_negative_jump" + in: + differences: [-100000] + lower: -100000 + upper: 100000 + out: 100001 + - name: "alternating_small" + in: + differences: [1, -1, 1, -1, 1, -1] + lower: 0 + upper: 1 + out: 1 + - name: "alternating_large" + in: + differences: [100000, -100000, 100000] + lower: -100000 + upper: 100000 + out: 100001 + - name: "negative_bounds" + in: + differences: [2, -1, -1] + lower: -100000 + upper: -99999 + out: 0 + - name: "one_width_range_flat" + in: + differences: [0, 0, 0, 0] + lower: 42 + upper: 42 + out: 1 + - name: "one_width_range_moving" + in: + differences: [0, 1] + lower: 42 + upper: 42 + out: 0 + - name: "plateau_prefix" + in: + differences: [3, 0, 0, -1] + lower: 0 + upper: 4 + out: 2 + - name: "minimum_at_end" + in: + differences: [2, 2, -10] + lower: -8 + upper: 2 + out: 1 + - name: "maximum_at_end" + in: + differences: [-2, -2, 10] + lower: -2 + upper: 8 + out: 1 + - name: "max_min_both" + in: + differences: [4, -8, 6, -3] + lower: -5 + upper: 5 + out: 3 + - name: "duplicates_cancel" + in: + differences: [2, 2, -2, -2] + lower: 10 + upper: 15 + out: 2 + - name: "range_boundary_one_extra" + in: + differences: [2, -4] + lower: 0 + upper: 4 + out: 1 + - name: "range_boundary_two_extra" + in: + differences: [2, -4] + lower: 0 + upper: 5 + out: 2 + - name: "repeated_maximum" + in: + differences: [7, 0, 0, -3] + lower: -10 + upper: 0 + out: 4 + - name: "repeated_minimum" + in: + differences: [-7, 0, 0, 3] + lower: 0 + upper: 10 + out: 4 + - name: "mixed_zeroes" + in: + differences: [0, -4, 0, 4, 0] + lower: -3 + upper: 3 + out: 3 + - name: "mixed_zeroes_wide" + in: + differences: [0, -4, 0, 4, 0] + lower: -10 + upper: 10 + out: 17 + - name: "near_coordinate_limits" + in: + differences: [100000, -100000, -100000] + lower: -100000 + upper: 100000 + out: 1 + - name: "generated_small" + seed: 101 + in: + differences: + gen: "array" + len: + gen: "int" + min: 1 + max: 20 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + lower: + gen: "int" + min: -100000 + max: 0 + upper: + gen: "int" + min: 0 + max: 100000 + - name: "generated_medium" + seed: 102 + in: + differences: + gen: "array" + len: + gen: "int" + min: 100 + max: 500 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + lower: -100000 + upper: 100000 + - name: "generated_large_positive" + seed: 103 + in: + differences: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 100000 + distinct: false + sorted: false + lower: -100000 + upper: 100000 + - name: "generated_large_mixed" + seed: 104 + in: + differences: + gen: "array" + len: 100000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + lower: -100000 + upper: 100000 + - name: "generated_limit_values" + seed: 105 + in: + differences: + gen: "array" + len: + gen: "int" + min: 1000 + max: 5000 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + lower: + gen: "int" + min: -100000 + max: -50000 + upper: + gen: "int" + min: 50000 + max: 100000 diff --git a/tests/2001-2500/2145. count-the-hidden-sequences/sol.py b/tests/2001-2500/2145. count-the-hidden-sequences/sol.py new file mode 100644 index 00000000..fde86238 --- /dev/null +++ b/tests/2001-2500/2145. count-the-hidden-sequences/sol.py @@ -0,0 +1,8 @@ +class Solution(object): + def numberOfArrays(self, differences, lower, upper): + sum, maxi, mini = 0, 0, 0 + for x in differences: + sum += x + maxi = max(maxi, sum) + mini = min(mini, sum) + return max(0, upper - lower - maxi + mini + 1) \ No newline at end of file diff --git a/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/manifest.yaml b/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/manifest.yaml new file mode 100644 index 00000000..61c376d8 --- /dev/null +++ b/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/manifest.yaml @@ -0,0 +1,385 @@ +entry: + id: 2146 + title: "k-highest-ranked-items-within-a-price-range" + params: + grid: + type: array + items: + type: array + items: + type: int + pricing: + type: array + items: + type: int + start: + type: array + items: + type: int + k: + type: int + call: + cpp: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + rust: "Solution::highest_ranked_k_items({grid}, {pricing}, {start}, {k})" + python3: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + python2: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + ruby: "highest_ranked_k_items({grid}, {pricing}, {start}, {k})" + java: "new Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + csharp: "new Solution().HighestRankedKItems({grid}, {pricing}, {start}, {k})" + kotlin: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + go: "highestRankedKItems({grid}, {pricing}, {start}, {k})" + dart: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + swift: "Solution().highestRankedKItems({grid}, {pricing}, {start}, {k})" + typescript: "highestRankedKItems({grid}, {pricing}, {start}, {k})" +judge: + type: exact +limits: + time_ms: 1000 + memory_mb: 512 +oracle: + python3: + call: "Checker().highestRankedKItems(grid, pricing, start, k, {result})" + checker: | + from collections import deque + class Checker: + def highestRankedKItems(self, grid, pricing, start, k, result): + m, n = len(grid), len(grid[0]) + low, high = pricing + sr, sc = start + q = deque([(sr, sc, 0)]) + seen = {(sr, sc)} + ranked = [] + while q: + r, c, d = q.popleft() + v = grid[r][c] + if low <= v <= high: + ranked.append((d, v, r, c)) + for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)): + nr, nc = r + dr, c + dc + if 0 <= nr < m and 0 <= nc < n and (nr, nc) not in seen and grid[nr][nc] != 0: + seen.add((nr, nc)) + q.append((nr, nc, d + 1)) + expected = [[r, c] for _, _, r, c in sorted(ranked)[:k]] + return result == expected +seed: 2146 +tests: + - name: "example_1" + in: + grid: + - [1, 2, 0, 1] + - [1, 3, 0, 1] + - [0, 2, 5, 1] + pricing: [2, 5] + start: [0, 0] + k: 3 + - name: "example_2" + in: + grid: + - [1, 2, 0, 1] + - [1, 3, 3, 1] + - [0, 2, 5, 1] + pricing: [2, 3] + start: [2, 3] + k: 2 + - name: "example_3" + in: + grid: + - [1, 1, 1] + - [0, 0, 1] + - [2, 3, 4] + pricing: [2, 3] + start: [0, 0] + k: 3 + - name: "single_start_item" + in: + grid: + - [2] + pricing: [2, 2] + start: [0, 0] + k: 1 + - name: "single_out_of_range" + in: + grid: + - [1] + pricing: [2, 2] + start: [0, 0] + k: 1 + - name: "one_row_price_ties" + in: + grid: + - [1, 5, 2, 5, 2, 5] + pricing: [2, 5] + start: [0, 0] + k: 6 + - name: "one_column" + in: + grid: + - [1] + - [4] + - [3] + - [2] + pricing: [2, 4] + start: [0, 0] + k: 2 + - name: "all_walls_except_start" + in: + grid: + - [7, 0, 6] + - [0, 1, 0] + - [5, 0, 4] + pricing: [2, 7] + start: [1, 1] + k: 4 + - name: "isolated_start_item" + in: + grid: + - [9, 0, 2] + - [0, 1, 0] + - [3, 0, 4] + pricing: [2, 9] + start: [0, 0] + k: 3 + - name: "inclusive_low" + in: + grid: + - [1, 2, 3] + pricing: [2, 2] + start: [0, 0] + k: 3 + - name: "inclusive_high" + in: + grid: + - [1, 4, 5] + pricing: [2, 5] + start: [0, 0] + k: 3 + - name: "k_one" + in: + grid: + - [1, 9, 2] + - [3, 4, 5] + pricing: [2, 9] + start: [0, 0] + k: 1 + - name: "k_all" + in: + grid: + - [2, 3] + - [4, 5] + pricing: [2, 5] + start: [0, 0] + k: 4 + - name: "same_distance_price_order" + in: + grid: + - [1, 9, 1] + - [8, 1, 7] + - [1, 6, 1] + pricing: [6, 9] + start: [1, 1] + k: 4 + - name: "same_distance_row_order" + in: + grid: + - [1, 5, 1, 5, 1] + - [5, 1, 5, 1, 5] + pricing: [5, 5] + start: [0, 2] + k: 5 + - name: "same_row_column_order" + in: + grid: + - [1, 2, 1, 3, 1] + pricing: [2, 3] + start: [0, 2] + k: 2 + - name: "zero_price_excluded" + in: + grid: + - [1, 0, 2] + - [3, 1, 4] + pricing: [2, 4] + start: [0, 0] + k: 4 + - name: "detour_around_walls" + in: + grid: + - [1, 0, 0, 5] + - [2, 1, 1, 1] + - [3, 0, 4, 6] + pricing: [2, 6] + start: [0, 0] + k: 5 + - name: "unreachable_right_region" + in: + grid: + - [1, 2, 0, 8] + - [3, 4, 0, 9] + - [5, 6, 0, 7] + pricing: [2, 9] + start: [0, 0] + k: 8 + - name: "start_high_price" + in: + grid: + - [100000, 2] + - [3, 4] + pricing: [2, 100000] + start: [0, 0] + k: 3 + - name: "maximum_price_boundary" + in: + grid: + - [1, 100000, 99999] + pricing: [99999, 100000] + start: [0, 0] + k: 2 + - name: "large_k_fewer_items" + in: + grid: + - [1, 2, 1] + - [1, 1, 1] + pricing: [2, 2] + start: [1, 1] + k: 6 + - name: "price_then_coordinates" + in: + grid: + - [1, 8, 1, 7] + - [6, 1, 5, 1] + - [1, 4, 1, 3] + pricing: [3, 8] + start: [1, 1] + k: 7 + - name: "blocked_start_component" + in: + grid: + - [2, 0, 3, 4] + - [0, 1, 0, 1] + - [5, 1, 6, 1] + pricing: [2, 6] + start: [1, 1] + k: 5 + - name: "rectangular_four_by_two" + in: + grid: + - [1, 2] + - [3, 4] + - [5, 6] + - [7, 8] + pricing: [3, 7] + start: [3, 1] + k: 4 + - name: "rectangular_two_by_four" + in: + grid: + - [1, 2, 3, 4] + - [8, 7, 6, 5] + pricing: [2, 7] + start: [0, 0] + k: 5 + - name: "many_equal_prices" + in: + grid: + - [1, 2, 2] + - [2, 1, 2] + - [2, 2, 1] + pricing: [2, 2] + start: [1, 1] + k: 8 + - name: "zero_wall_corridor" + in: + grid: + - [1, 2, 0, 0, 3] + - [1, 1, 1, 1, 1] + - [4, 0, 0, 0, 5] + pricing: [2, 5] + start: [0, 0] + k: 4 + - name: "start_empty_cell" + in: + grid: + - [5, 1, 2] + - [4, 1, 3] + pricing: [2, 5] + start: [0, 1] + k: 4 + - name: "narrow_turns" + in: + grid: + - [1, 2, 0, 0] + - [0, 1, 3, 0] + - [0, 0, 1, 4] + - [8, 7, 6, 5] + pricing: [2, 8] + start: [0, 0] + k: 6 + - name: "all_cells_items" + in: + grid: + - [2, 3, 4] + - [5, 6, 7] + - [8, 9, 10] + pricing: [2, 10] + start: [1, 1] + k: 9 + - name: "lower_bound_two" + in: + grid: + - [1, 2, 1] + - [2, 1, 2] + pricing: [2, 2] + start: [0, 0] + k: 3 + - name: "high_bound_one_hundred_thousand" + in: + grid: + - [1, 99998, 100000] + - [99999, 1, 2] + pricing: [99998, 100000] + start: [1, 1] + k: 3 + - name: "large_open_grid" + in: + grid: + - [1, 2, 3, 4, 5, 6, 7, 8] + - [16, 15, 14, 13, 12, 11, 10, 9] + - [17, 18, 19, 20, 21, 22, 23, 24] + - [32, 31, 30, 29, 28, 27, 26, 25] + - [33, 34, 35, 36, 37, 38, 39, 40] + - [48, 47, 46, 45, 44, 43, 42, 41] + - [49, 50, 51, 52, 53, 54, 55, 56] + - [64, 63, 62, 61, 60, 59, 58, 57] + pricing: [20, 50] + start: [0, 0] + k: 20 + - name: "large_walled_grid" + in: + grid: + - [1, 2, 0, 4, 5, 0, 7, 8] + - [9, 10, 0, 12, 13, 0, 15, 16] + - [17, 18, 19, 20, 0, 22, 23, 24] + - [0, 26, 27, 28, 0, 30, 31, 0] + - [33, 34, 0, 36, 37, 38, 0, 40] + - [41, 0, 43, 44, 45, 0, 47, 48] + pricing: [2, 48] + start: [0, 0] + k: 18 + - name: "far_corner_start" + in: + grid: + - [2, 1, 3, 1] + - [4, 1, 5, 1] + - [6, 1, 7, 1] + - [8, 1, 9, 1] + pricing: [2, 9] + start: [3, 3] + k: 7 + - name: "no_matching_reachable_items" + in: + grid: + - [1, 1, 0] + - [1, 1, 2] + pricing: [3, 4] + start: [0, 0] + k: 2 diff --git a/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/sol.py b/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/sol.py new file mode 100644 index 00000000..97f89fe2 --- /dev/null +++ b/tests/2001-2500/2146. k-highest-ranked-items-within-a-price-range/sol.py @@ -0,0 +1,34 @@ +class Solution(object): + def highestRankedKItems(self, grid, pricing, start, k): + """ + :type grid: List[List[int]] + :type pricing: List[int] + :type start: List[int] + :type k: int + :rtype: List[List[int]] + """ + m, n = len(grid), len(grid[0]) + low, high = pricing + sr, sc = start + + q = deque([(sr, sc, 0)]) + visited = set([(sr, sc)]) + items = [] + + directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] + + while q: + r, c, dist = q.popleft() + val = grid[r][c] + + if low <= val <= high: + items.append((dist, val, r, c)) + + for dr, dc in directions: + nr, nc = r + dr, c + dc + if 0 <= nr < m and 0 <= nc < n and (nr, nc) not in visited and grid[nr][nc] != 0: + visited.add((nr, nc)) + q.append((nr, nc, dist + 1)) + + items.sort() + return [[r, c] for _, _, r, c in items[:k]] \ No newline at end of file diff --git a/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/manifest.yaml b/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/manifest.yaml new file mode 100644 index 00000000..4dbae1cb --- /dev/null +++ b/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/manifest.yaml @@ -0,0 +1,214 @@ +entry: + id: 2147 + title: "number-of-ways-to-divide-a-long-corridor" + params: + corridor: + type: string + call: + cpp: "Solution().numberOfWays({corridor})" + rust: "Solution::number_of_ways({corridor})" + python3: "Solution().numberOfWays({corridor})" + python2: "Solution().numberOfWays({corridor})" + ruby: "number_of_ways({corridor})" + java: "new Solution().numberOfWays({corridor})" + csharp: "new Solution().NumberOfWays({corridor})" + kotlin: "Solution().numberOfWays({corridor})" + go: "numberOfWays({corridor})" + dart: "Solution().numberOfWays({corridor})" + swift: "Solution().numberOfWays({corridor})" + typescript: "numberOfWays({corridor})" + +judge: + type: "exact" + +limits: + time_ms: 500 + memory_mb: 300 + +oracle: + python3: + call: "Checker().numberOfWays(corridor, {result})" + checker: | + class Checker: + def numberOfWays(self, corridor, result): + if not isinstance(result, int) or isinstance(result, bool): + return False + mod = 1000000007 + seats = [i for i, c in enumerate(corridor) if c == 'S'] + if len(seats) == 0 or len(seats) % 2: + expected = 0 + else: + expected = 1 + for i in range(1, len(seats) - 1, 2): + expected = expected * (seats[i + 1] - seats[i]) % mod + return result == expected + +seed: 2147 + +tests: + - name: "single_seat" + in: + corridor: "S" + out: 0 + - name: "single_plant" + in: + corridor: "P" + out: 0 + - name: "empty_pair" + in: + corridor: "PP" + out: 0 + - name: "two_adjacent_seats" + in: + corridor: "SS" + out: 1 + - name: "seat_then_plant" + in: + corridor: "SP" + out: 0 + - name: "plant_then_seat" + in: + corridor: "PS" + out: 0 + - name: "pair_with_trailing_plants" + in: + corridor: "SSPPP" + out: 1 + - name: "leading_plants_pair" + in: + corridor: "PPPSS" + out: 1 + - name: "one_gap_between_pairs" + in: + corridor: "SSPSS" + out: 2 + - name: "two_gap_between_pairs" + in: + corridor: "SSPPSS" + out: 3 + - name: "three_gap_between_pairs" + in: + corridor: "SSPPPSS" + out: 4 + - name: "example_one" + in: + corridor: "SSPPSPS" + out: 3 + - name: "example_two" + in: + corridor: "PPSPSP" + out: 1 + - name: "four_seats_adjacent" + in: + corridor: "SSSS" + out: 1 + - name: "six_seats_adjacent" + in: + corridor: "SSSSSS" + out: 1 + - name: "eight_seats_adjacent" + in: + corridor: "SSSSSSSS" + out: 1 + - name: "odd_three_seats" + in: + corridor: "SSPS" + out: 0 + - name: "odd_five_seats" + in: + corridor: "SPSPS" + out: 0 + - name: "odd_seven_seats" + in: + corridor: "SSPPSSPS" + out: 0 + - name: "alternating_five" + in: + corridor: "PSPSP" + out: 1 + - name: "two_pairs_leading_gap" + in: + corridor: "PSSPPSSP" + out: 3 + - name: "two_pairs_long_gap" + in: + corridor: "SSPPPPSS" + out: 5 + - name: "three_pairs_mixed" + in: + corridor: "PPSSPPSSPP" + out: 3 + - name: "three_pairs_many_plants" + in: + corridor: "SSPPSSPPSSPPSS" + out: 27 + - name: "four_pairs_mixed" + in: + corridor: "SPSPSSPPSSPS" + out: 0 + - name: "long_first_gap" + in: + corridor: "PSSPPPPPPPSS" + out: 8 + - name: "long_leading_and_trailing" + in: + corridor: "PPSSPPSSPPSSPP" + out: 9 + - name: "twenty_plant_gap" + in: + corridor: "PPPPPPPPPPPPPPPPPPPPSSPPPPPPPPPPPPPPPPPPPPSS" + out: 21 + - name: "one_hundred_seats_even" + in: + corridor: "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" + out: 1 + - name: "one_hundred_one_seats_odd" + in: + corridor: "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" + out: 0 + - name: "plants_then_pair_at_end" + in: + corridor: "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPSS" + out: 1 + - name: "pair_long_middle_gap" + in: + corridor: "SSPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPSS" + out: 92 + - name: "generated_small_balanced" + seed: 31 + in: + corridor: + gen: "str" + len: 17 + alphabet: "SP" + - name: "generated_small_varied" + seed: 32 + in: + corridor: + gen: "str" + len: + gen: "int" + min: 1 + max: 60 + alphabet: "SP" + - name: "generated_medium" + seed: 33 + in: + corridor: + gen: "str" + len: 1000 + alphabet: "SP" + - name: "generated_large" + seed: 34 + in: + corridor: + gen: "str" + len: 50000 + alphabet: "SP" + - name: "generated_maximum" + seed: 35 + in: + corridor: + gen: "str" + len: 100000 + alphabet: "SP" diff --git a/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/sol.py b/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/sol.py new file mode 100644 index 00000000..2c26572f --- /dev/null +++ b/tests/2001-2500/2147. number-of-ways-to-divide-a-long-corridor/sol.py @@ -0,0 +1,8 @@ +class Solution(object): + def numberOfWays(self, corridor): + mod = 10**9 + 7 + s0 = s1 = 0; s2 = 1 + for c in corridor: + if c == 'S': s0, s1, s2 = s1, s2, s1 + else: s2 = (s2 + s0) % mod + return s0 \ No newline at end of file diff --git a/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/manifest.yaml b/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/manifest.yaml new file mode 100644 index 00000000..7065e49b --- /dev/null +++ b/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/manifest.yaml @@ -0,0 +1,220 @@ +entry: + id: 2148 + title: "count-elements-with-strictly-smaller-and-greater-elements" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().countElements({nums})" + rust: "Solution::count_elements({nums})" + python3: "Solution().countElements({nums})" + python2: "Solution().countElements({nums})" + ruby: "count_elements({nums})" + java: "new Solution().countElements({nums})" + csharp: "new Solution().CountElements({nums})" + kotlin: "Solution().countElements({nums})" + go: "countElements({nums})" + dart: "Solution().countElements({nums})" + swift: "Solution().countElements({nums})" + typescript: "countElements({nums})" +judge: + type: "exact" +limits: + time_ms: 1000 + memory_mb: 128 +oracle: + python3: + call: "Checker().countElements(nums, {result})" + checker: | + class Checker: + def countElements(self, nums, result): + return isinstance(result, int) and result == sum(min(nums) < x < max(nums) for x in nums) +seed: 2148 +tests: + - name: "example-one" + in: + nums: [11, 7, 2, 15] + out: 2 + - name: "example-two" + in: + nums: [-3, 3, 3, 90] + out: 2 + - name: "single" + in: + nums: [7] + out: 0 + - name: "two-different" + in: + nums: [1, 2] + out: 0 + - name: "all-equal" + in: + nums: [5, 5, 5, 5] + out: 0 + - name: "three-distinct" + in: + nums: [1, 2, 3] + out: 1 + - name: "middle-duplicates" + in: + nums: [1, 2, 2, 2, 3] + out: 3 + - name: "min-duplicates" + in: + nums: [1, 1, 2, 3] + out: 1 + - name: "max-duplicates" + in: + nums: [1, 2, 3, 3] + out: 1 + - name: "negative-range" + in: + nums: [-5, -4, -3, -2, -1] + out: 3 + - name: "extreme-values" + in: + nums: [-100000, 0, 100000] + out: 1 + - name: "unsorted" + in: + nums: [9, 1, 8, 2, 7, 3] + out: 4 + - name: "only-extremes" + in: + nums: [1, 1, 10, 10] + out: 0 + - name: "zero-center" + in: + nums: [-1, 0, 1] + out: 1 + - name: "many-middle-values" + in: + nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + out: 9 + - name: "one-middle-among-duplicates" + in: + nums: [0, 0, 5, 10, 10] + out: 1 + - name: "alternating-extremes" + in: + nums: [1, 9, 1, 9, 5] + out: 1 + - name: "all-middle-same" + in: + nums: [-10, 4, 4, 4, 10] + out: 3 + - name: "four-levels" + in: + nums: [4, 1, 3, 2] + out: 2 + - name: "ascending-hundred" + in: + nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] + out: 18 + - name: "generated-small" + seed: 1 + in: + nums: + gen: "array" + len: 5 + of: + gen: "int" + min: -10 + max: 10 + distinct: false + sorted: false + elemType: "int" + - name: "generated-medium" + seed: 2 + in: + nums: + gen: "array" + len: 50 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-maximum" + seed: 3 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: -100000 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-narrow-range" + seed: 4 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: -2 + max: 2 + distinct: false + sorted: false + elemType: "int" + - name: "generated-positive" + seed: 5 + in: + nums: + gen: "array" + len: 100 + of: + gen: "int" + min: 1 + max: 100000 + distinct: false + sorted: false + elemType: "int" + - name: "three-equal" + in: + nums: [-2, -2, -2] + out: 0 + - name: "middle-at-front" + in: + nums: [5, 1, 9] + out: 1 + - name: "middle-at-end" + in: + nums: [1, 9, 5] + out: 1 + - name: "large-negative-middle" + in: + nums: [-100000, -99999, 100000] + out: 1 + - name: "all-values-middle" + in: + nums: [10, 20, 20, 20, 30] + out: 3 + - name: "four-middle-values" + in: + nums: [0, 1, 1, 2, 2, 3] + out: 4 + - name: "duplicate-extremes-and-middle" + in: + nums: [-5, -5, 0, 0, 5, 5] + out: 2 + - name: "wide-unsorted" + in: + nums: [100, -100, 50, -50, 0] + out: 3 + - name: "one-hundred-equal" + in: + nums: [42, 42, 42, 42, 42, 42, 42, 42, 42, 42] + out: 0 + - name: "smallest-and-largest-repeated" + in: + nums: [1, 3, 5, 1, 3, 5, 3] + out: 3 diff --git a/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/sol.py b/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/sol.py new file mode 100644 index 00000000..7ff1d1ac --- /dev/null +++ b/tests/2001-2500/2148. count-elements-with-strictly-smaller-and-greater-elements/sol.py @@ -0,0 +1,9 @@ +class Solution: + def countElements(self, nums): + maxEle = max(nums) + minEle = min(nums) + count = 0 + for num in nums: + if num != minEle and num != maxEle: + count += 1 + return count \ No newline at end of file diff --git a/tests/2001-2500/2149. rearrange-array-elements-by-sign/manifest.yaml b/tests/2001-2500/2149. rearrange-array-elements-by-sign/manifest.yaml new file mode 100644 index 00000000..0db8c11a --- /dev/null +++ b/tests/2001-2500/2149. rearrange-array-elements-by-sign/manifest.yaml @@ -0,0 +1,191 @@ +entry: + id: 2149 + title: "rearrange-array-elements-by-sign" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().rearrangeArray({nums})" + rust: "Solution::rearrange_array({nums})" + python3: "Solution().rearrangeArray({nums})" + python2: "Solution().rearrangeArray({nums})" + ruby: "rearrange_array({nums})" + java: "new Solution().rearrangeArray({nums})" + csharp: "new Solution().RearrangeArray({nums})" + kotlin: "Solution().rearrangeArray({nums})" + go: "rearrangeArray({nums})" + dart: "Solution().rearrangeArray({nums})" + swift: "Solution().rearrangeArray({nums})" + typescript: "rearrangeArray({nums})" + +judge: + type: "exact" + +limits: + time_ms: 1000 + memory_mb: 300 + +oracle: + python3: + call: "Checker().rearrangeArray(nums, {result})" + checker: | + class Checker: + def rearrangeArray(self, nums, result): + if not isinstance(result, list) or len(result) != len(nums): + return False + positives = [x for x in nums if x > 0] + negatives = [x for x in nums if x < 0] + expected = [] + for p, n in zip(positives, negatives): + expected.extend([p, n]) + return result == expected + +seed: 2149 + +tests: + - name: "example_mixed" + in: + nums: [3, 1, -2, -5, 2, -4] + out: [3, -2, 1, -5, 2, -4] + - name: "example_single_pair_reversed" + in: + nums: [-1, 1] + out: [1, -1] + - name: "already_alternating" + in: + nums: [1, -1, 2, -2, 3, -3] + out: [1, -1, 2, -2, 3, -3] + - name: "all_negatives_first" + in: + nums: [-1, -2, -3, 1, 2, 3] + out: [1, -1, 2, -2, 3, -3] + - name: "all_positives_first" + in: + nums: [7, 8, 9, -7, -8, -9] + out: [7, -7, 8, -8, 9, -9] + - name: "negative_positive_blocks" + in: + nums: [-5, -4, 6, 7, -3, 8, -2, 9] + out: [6, -5, 7, -4, 8, -3, 9, -2] + - name: "duplicate_values" + in: + nums: [5, -5, 5, -5, 5, -5] + out: [5, -5, 5, -5, 5, -5] + - name: "duplicate_sign_runs" + in: + nums: [-2, 4, -2, 4, -2, 4, -2, 4] + out: [4, -2, 4, -2, 4, -2, 4, -2] + - name: "minimum_magnitude" + in: + nums: [1, -1, -1, 1, 1, -1, 1, -1] + out: [1, -1, 1, -1, 1, -1, 1, -1] + - name: "maximum_magnitude" + in: + nums: [100000, -100000, 99999, -99999] + out: [100000, -100000, 99999, -99999] + - name: "alternating_signs_start_negative" + in: + nums: [-10, 20, -30, 40, -50, 60, -70, 80] + out: [20, -10, 40, -30, 60, -50, 80, -70] + - name: "interleaved_with_runs" + in: + nums: [12, -1, -2, 13, 14, -3, -4, -5, 15, 16] + out: [12, -1, 13, -2, 14, -3, 15, -4, 16, -5] + - name: "positives_in_descending_order" + in: + nums: [9, -1, 8, -2, 7, -3, 6, -4] + out: [9, -1, 8, -2, 7, -3, 6, -4] + - name: "negatives_in_descending_order" + in: + nums: [1, -9, 2, -8, 3, -7, 4, -6] + out: [1, -9, 2, -8, 3, -7, 4, -6] + - name: "positives_scrambled_positions" + in: + nums: [-1, 30, -2, 10, -3, 20] + out: [30, -1, 10, -2, 20, -3] + - name: "negatives_scrambled_positions" + in: + nums: [4, -30, 5, -10, 6, -20] + out: [4, -30, 5, -10, 6, -20] + - name: "eight_values" + in: + nums: [2, 4, -1, -3, 6, -5, -7, 8] + out: [2, -1, 4, -3, 6, -5, 8, -7] + - name: "ten_values" + in: + nums: [-1, 11, -2, -3, 12, -4, 13, -5, 14, 15] + out: [11, -1, 12, -2, 13, -3, 14, -4, 15, -5] + - name: "balanced_blocks_ten" + in: + nums: [1, 2, 3, 4, 5, -5, -4, -3, -2, -1] + out: [1, -5, 2, -4, 3, -3, 4, -2, 5, -1] + - name: "large_gaps" + in: + nums: [99999, -1, 2, -99998, 50000, -50000] + out: [99999, -1, 2, -99998, 50000, -50000] + - name: "repeated_extremes" + in: + nums: [-100000, 100000, -100000, 100000, -100000, 100000] + out: [100000, -100000, 100000, -100000, 100000, -100000] + - name: "twelve_values" + in: + nums: [6, -6, -7, 5, 4, -8, -9, 3, 2, -10, 1, -11] + out: [6, -6, 5, -7, 4, -8, 3, -9, 2, -10, 1, -11] + - name: "positive_order_requires_stability" + in: + nums: [-4, 8, 3, -5, 9, -6, 2, -7] + out: [8, -4, 3, -5, 9, -6, 2, -7] + - name: "negative_order_requires_stability" + in: + nums: [8, -3, 7, -1, 6, -2, 5, -4] + out: [8, -3, 7, -1, 6, -2, 5, -4] + - name: "sixteen_values" + in: + nums: [-1, -2, 10, -3, 11, 12, -4, -5, 13, 14, -6, 15, -7, -8, 16, 17] + out: [10, -1, 11, -2, 12, -3, 13, -4, 14, -5, 15, -6, 16, -7, 17, -8] + - name: "mixed_magnitudes" + in: + nums: [1, -100000, 99999, -2, 3, -99999, 4, -100] + out: [1, -100000, 99999, -2, 3, -99999, 4, -100] + - name: "positives_clustered_end" + in: + nums: [-1, -2, -3, -4, 1, 2, 3, 4] + out: [1, -1, 2, -2, 3, -3, 4, -4] + - name: "negatives_clustered_end" + in: + nums: [1, 2, 3, 4, -1, -2, -3, -4] + out: [1, -1, 2, -2, 3, -3, 4, -4] + - name: "twenty_values" + in: + nums: [20, -1, -2, 19, 18, -3, 17, -4, -5, 16, 15, -6, 14, -7, 13, -8, -9, 12, 11, -10] + out: [20, -1, 19, -2, 18, -3, 17, -4, 16, -5, 15, -6, 14, -7, 13, -8, 12, -9, 11, -10] + - name: "distinct_values_preserved" + in: + nums: [42, -17, 6, -88, 73, -2] + out: [42, -17, 6, -88, 73, -2] + - name: "odd_value_magnitudes" + in: + nums: [-99999, 1, -77777, 3, -55555, 5] + out: [1, -99999, 3, -77777, 5, -55555] + - name: "order_across_long_runs" + in: + nums: [4, 8, -1, -2, -3, 10, 12, 14, -5, 16, -6, -7] + out: [4, -1, 8, -2, 10, -3, 12, -5, 14, -6, 16, -7] + - name: "twenty_four_values" + in: + nums: [-1, 2, -3, 4, -5, -6, 8, 10, -7, 12, 14, -9, -11, 16, 18, -13, 20, -15, -17, 22, 24, -19, -21, 26] + out: [2, -1, 4, -3, 8, -5, 10, -6, 12, -7, 14, -9, 16, -11, 18, -13, 20, -15, 22, -17, 24, -19, 26, -21] + - name: "thirty_two_values" + in: + nums: [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16] + out: [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16] + - name: "thirty_four_values" + in: + nums: [-1, -2, 1, -3, 2, -4, 3, -5, 4, -6, 5, -7, 6, -8, 7, -9, 8, -10, 9, -11, 10, -12, 11, -13, 12, -14, 13, -15, 14, -16, 15, -17, 16, 17] + out: [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17] + - name: "forty_values" + in: + nums: [100000, -100000, 99999, -99999, 99998, -99998, 99997, -99997, 99996, -99996, 99995, -99995, 99994, -99994, 99993, -99993, 99992, -99992, 99991, -99991, 99990, -99990, 99989, -99989, 99988, -99988, 99987, -99987, 99986, -99986, 99985, -99985, 99984, -99984, 99983, -99983, 99982, -99982, 99981, -99981] + out: [100000, -100000, 99999, -99999, 99998, -99998, 99997, -99997, 99996, -99996, 99995, -99995, 99994, -99994, 99993, -99993, 99992, -99992, 99991, -99991, 99990, -99990, 99989, -99989, 99988, -99988, 99987, -99987, 99986, -99986, 99985, -99985, 99984, -99984, 99983, -99983, 99982, -99982, 99981, -99981] diff --git a/tests/2001-2500/2149. rearrange-array-elements-by-sign/sol.py b/tests/2001-2500/2149. rearrange-array-elements-by-sign/sol.py new file mode 100644 index 00000000..73830a82 --- /dev/null +++ b/tests/2001-2500/2149. rearrange-array-elements-by-sign/sol.py @@ -0,0 +1,15 @@ +class Solution: + def rearrangeArray(self, nums: List[int]) -> List[int]: + pos, neg = [], [] + + for n in nums: + if n > 0: + pos.append(n) + else: + neg.append(n) + + res = [0] * len(nums) + res[0 : len(pos) * 2 : 2] = pos + res[1 : len(neg) * 2 : 2] = neg + + return res \ No newline at end of file diff --git a/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/manifest.yaml b/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/manifest.yaml new file mode 100644 index 00000000..fbf24d94 --- /dev/null +++ b/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/manifest.yaml @@ -0,0 +1,225 @@ +entry: + id: 2150 + title: "find-all-lonely-numbers-in-the-array" + params: + nums: + type: array + items: + type: int + call: + cpp: "Solution().findLonely({nums})" + rust: "Solution::find_lonely({nums})" + python3: "Solution().findLonely({nums})" + python2: "Solution().findLonely({nums})" + ruby: "find_lonely({nums})" + java: "new Solution().findLonely({nums})" + csharp: "new Solution().FindLonely({nums})" + kotlin: "Solution().findLonely({nums})" + go: "findLonely({nums})" + dart: "Solution().findLonely({nums})" + swift: "Solution().findLonely({nums})" + typescript: "findLonely({nums})" +judge: + type: "ignore_order" +limits: + time_ms: 1000 + memory_mb: 256 +oracle: + python3: + call: "Checker().findLonely(nums, {result})" + checker: | + from collections import Counter + class Checker: + def findLonely(self, nums, result): + if not isinstance(result, list) or any(not isinstance(x, int) for x in result): + return False + counts = Counter(nums) + expected = {x for x, count in counts.items() if count == 1 and x - 1 not in counts and x + 1 not in counts} + return len(result) == len(set(result)) and set(result) == expected +seed: 2150 +tests: + - name: "example-one" + in: + nums: [10, 6, 5, 8] + out: [10, 8] + - name: "example-two" + in: + nums: [1, 3, 5, 3] + out: [1, 5] + - name: "single" + in: + nums: [0] + out: [0] + - name: "two-adjacent" + in: + nums: [0, 1] + out: [] + - name: "two-separated" + in: + nums: [0, 2] + out: [0, 2] + - name: "all-duplicates" + in: + nums: [7, 7, 7] + out: [] + - name: "consecutive-run" + in: + nums: [1, 2, 3, 4, 5] + out: [] + - name: "gapped-values" + in: + nums: [1, 3, 5, 7] + out: [1, 3, 5, 7] + - name: "duplicate-blocks" + in: + nums: [1, 1, 3, 3, 5, 5] + out: [] + - name: "duplicate-neighbor" + in: + nums: [2, 2, 4, 6] + out: [4, 6] + - name: "zero-boundary" + in: + nums: [0, 2, 2, 4] + out: [0, 4] + - name: "max-value" + in: + nums: [1000000] + out: [1000000] + - name: "near-maximum-adjacent" + in: + nums: [999999, 1000000] + out: [] + - name: "three-isolated" + in: + nums: [10, 20, 30] + out: [10, 20, 30] + - name: "middle-duplicate" + in: + nums: [1, 5, 5, 9] + out: [1, 9] + - name: "unsorted-consecutive" + in: + nums: [9, 7, 8, 1] + out: [1] + - name: "negative-not-applicable" + in: + nums: [0, 100, 200] + out: [0, 100, 200] + - name: "neighbors-with-duplicate" + in: + nums: [4, 5, 5, 6] + out: [] + - name: "mixed-frequencies" + in: + nums: [1, 1, 10, 12, 12, 14] + out: [10, 14] + - name: "wide-range" + in: + nums: [0, 1000000, 500000] + out: [0, 1000000, 500000] + - name: "generated-small" + seed: 1 + in: + nums: + gen: "array" + len: 20 + of: + gen: "int" + min: 0 + max: 30 + distinct: false + sorted: false + elemType: "int" + - name: "generated-medium" + seed: 2 + in: + nums: + gen: "array" + len: 1000 + of: + gen: "int" + min: 0 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-large" + seed: 3 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + - name: "generated-narrow" + seed: 4 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: 0 + max: 100 + distinct: false + sorted: false + elemType: "int" + - name: "generated-high-values" + seed: 5 + in: + nums: + gen: "array" + len: 100000 + of: + gen: "int" + min: 999000 + max: 1000000 + distinct: false + sorted: false + elemType: "int" + - name: "one-among-neighbors" + in: + nums: [2, 3, 10] + out: [10] + - name: "two-lonely-around-duplicate" + in: + nums: [1, 1, 10, 20] + out: [10, 20] + - name: "large-gaps" + in: + nums: [11, 33, 55, 77, 99] + out: [11, 33, 55, 77, 99] + - name: "single-between-neighbors" + in: + nums: [4, 6, 8] + out: [4, 6, 8] + - name: "ten-consecutive" + in: + nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + out: [] + - name: "odd-values" + in: + nums: [1, 3, 5, 7, 9, 11] + out: [1, 3, 5, 7, 9, 11] + - name: "ends-with-duplicates" + in: + nums: [1, 1, 5, 9, 9] + out: [5] + - name: "isolated-and-adjacent" + in: + nums: [100, 101, 200, 300, 301] + out: [200] + - name: "repeated-isolated-value" + in: + nums: [100, 100, 200] + out: [200] + - name: "alternating-pairs" + in: + nums: [0, 1, 10, 11, 20, 21] + out: [] diff --git a/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/sol.py b/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/sol.py new file mode 100644 index 00000000..5ed0cb2c --- /dev/null +++ b/tests/2001-2500/2150. find-all-lonely-numbers-in-the-array/sol.py @@ -0,0 +1,21 @@ +class Solution(object): + def findLonely(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + res = [] + + freq = {} + + for x in range(len(nums)): + if nums[x] in freq: + freq[nums[x]]+=1 + else: + freq[nums[x]]=1 + + for frequency,value in freq.items(): + if value == 1: + if frequency + 1 not in freq and frequency - 1 not in freq: + res.append(frequency) + return res \ No newline at end of file